
#include	"SysConfig.h"
#include	"Define.h"
#include	"Function.h"
#include	"UI_Main.h"
#include	"Tuner.h"
#include	"Display.h"
#include	"Model_Option.h"
#include	"Key.h"
#include	"Port.h"
#ifdef  AV_CONTROLLER
#include	"AVController.h"
#endif
#ifdef  LC786XXX
#include	"LC786XXX.h"
#endif
#ifdef  CD
#include	"CD.h"
#endif
#include	"USB.h"
#include	"Boot_LC786.h"
#include	"Boot_Util.h"
#include	"Audio.h"

#ifdef  MIC
#include	"MIC.h"
#endif

#ifdef BLUETOOTH
#include	"Bluetooth.h"
#include	"Boot_Bluetooth.h"
#endif
#ifdef  AUTO_GUIDE
#include	"AutoGuide.h"
#endif
KEY_ID	ucKEY_MatrixKey;
KEY_ID	ucKEY_EncVolKey;
KEY_ID	ucKEY_EncTuneKey;
KEY_ID	ucKEY_RmcKey;
KEY_ID	ucKEY_New;
KEY_ID	ucKEY_Last;

unsigned char ucKEY_Rmc_Timer5msec;
unsigned char ucKEY_RmcInvalid_Timer5msec;
unsigned short usKEY_LongKey_Timer10msec;
unsigned char ucKEY_ShortKey_Timer5msec;
unsigned char ucKEY_Change_Timer5msec;
unsigned char ucKEY_EncVolKey_Timer5msec;
unsigned char ucKEY_Action;
unsigned char ucKEY_MatrixSeq;
unsigned char ucKEY_MatrixCnt;
unsigned char ucKEY_Matrix[4];
extern unsigned char DRV_LC786XXX_FirmwareUpdate_ON;
extern void DRV_LC786XXX_Get_FirmwareVersion(void);
extern unsigned short CPU_ADC_GetRemoconLevel(void);

#define	KEY_MATRIX_INPUT1		0x01
#define	KEY_MATRIX_INPUT2		0x02
#define	KEY_MATRIX_INPUT3		0x08
#define	KEY_MATRIX_INPUT4		0x10
#if  1
///////////////////// KEY OUT 1 //////////////////////////////
#define	KEY_MATRIX_O1I1		ucKEY_Matrix[0] & KEY_MATRIX_INPUT1	// KEY_IN1
#define	KEY_MATRIX_O1I2		ucKEY_Matrix[0] & KEY_MATRIX_INPUT2	// KEY_IN2
#define	KEY_MATRIX_O1I3		ucKEY_Matrix[0] & KEY_MATRIX_INPUT3	// KEY_IN3
#define	KEY_MATRIX_O1I4		ucKEY_Matrix[0] & KEY_MATRIX_INPUT4	// KEY_IN4

///////////////////// KEY OUT 2 //////////////////////////////
#define	KEY_MATRIX_O2I1		ucKEY_Matrix[1] & KEY_MATRIX_INPUT1	// KEY_IN1
#define	KEY_MATRIX_O2I2		ucKEY_Matrix[1] & KEY_MATRIX_INPUT2	// KEY_IN2
#define	KEY_MATRIX_O2I3		ucKEY_Matrix[1] & KEY_MATRIX_INPUT3	// KEY_IN3
#define	KEY_MATRIX_O2I4		ucKEY_Matrix[1] & KEY_MATRIX_INPUT4	// KEY_IN3

///////////////////// KEY OUT 3 //////////////////////////////
#define	KEY_MATRIX_O3I1		ucKEY_Matrix[2] & KEY_MATRIX_INPUT1	// KEY_IN1
#define	KEY_MATRIX_O3I2		ucKEY_Matrix[2] & KEY_MATRIX_INPUT2	// KEY_IN2
#define	KEY_MATRIX_O3I3		ucKEY_Matrix[2] & KEY_MATRIX_INPUT3	// KEY_IN3
#define	KEY_MATRIX_O3I4		ucKEY_Matrix[2] & KEY_MATRIX_INPUT4	// KEY_IN3

///////////////////// KEY OUT 4 //////////////////////////////
#define	KEY_MATRIX_O4I1		ucKEY_Matrix[3] & KEY_MATRIX_INPUT1	// KEY_IN1
#define	KEY_MATRIX_O4I2		ucKEY_Matrix[3] & KEY_MATRIX_INPUT2	// KEY_IN2
#define	KEY_MATRIX_O4I3		ucKEY_Matrix[3] & KEY_MATRIX_INPUT3	// KEY_IN3
#define	KEY_MATRIX_O4I4		ucKEY_Matrix[3] & KEY_MATRIX_INPUT4	// KEY_IN3
#else
///////////////////// KEY OUT 1 //////////////////////////////
#define	KEY_MATRIX_MODE		ucKEY_Matrix[0] & 0x01	// KEY_IN1
#define	KEY_MATRIX_NUM1		ucKEY_Matrix[0] & 0x02	// KEY_IN2
#define	KEY_MATRIX_NUM5		ucKEY_Matrix[0] & 0x04	// KEY_IN3
#define	KEY_MATRIX_TUNE		ucKEY_Matrix[0] & 0x08	// KEY_IN4

///////////////////// KEY OUT 2 //////////////////////////////
#define	KEY_MATRIX_CALL		ucKEY_Matrix[1] & 0x01	// KEY_IN1
#define	KEY_MATRIX_NUM2		ucKEY_Matrix[1] & 0x01	// KEY_IN2
#define	KEY_MATRIX_NUM5		ucKEY_Matrix[1] & 0x01	// KEY_IN3

///////////////////// KEY OUT 3 //////////////////////////////
#define	KEY_MATRIX_BAND		ucKEY_Matrix[2] & 0x01	// KEY_IN1
#define	KEY_MATRIX_NUM3		ucKEY_Matrix[2] & 0x01	// KEY_IN2
#define	KEY_MATRIX_HANG_UP	ucKEY_Matrix[2] & 0x01	// KEY_IN3

///////////////////// KEY OUT 4 //////////////////////////////
#define	KEY_MATRIX_MENU		ucKEY_Matrix[2] & 0x01	// KEY_IN1
#define	KEY_MATRIX_NUM4		ucKEY_Matrix[2] & 0x01	// KEY_IN2
#define	KEY_MATRIX_POWER	ucKEY_Matrix[2] & 0x01	// KEY_IN3
#endif

#ifdef  USB_DISABLE_TEST
unsigned char ucDisable_USB;
#endif

extern unsigned char ucFUNC_Power;
extern UI_MENU_ID ucMenuID;
extern UI_FUNCTION ucFUNC_Current;

#ifdef  USER_WATCHDOG
extern void CPU_WatchDogEnable(void);
#endif
extern void FUNC_SetInput(UI_FUNCTION ucFunc);
extern void FUNC_PowerOn(void);
extern void FUNC_PowerOff(void);
extern unsigned char FUNC_CheckFunctionAvailable(UI_FUNCTION ucFunc);
extern unsigned char FUNC_MediaChange(void);
extern unsigned char FUNC_SelectUSB(void);
extern unsigned char FUNC_SelectCD(void);

#ifdef  MODEL_ARA5040
extern unsigned char FUNC_SelectAux(void);
extern void AUDIO_ChangeLoud(void);
#endif

extern unsigned char ucAUDIO_Mute;
extern unsigned char ucAUDIO_TelMute;
extern void AUDIO_SetMute(unsigned char ucDes);
extern void AUDIO_VolumeChange(unsigned char ucDes);
extern void	AUDIO_BeepOutStart(void);
extern void AUDIO_SetAudio(void);
extern void AUDIO_EQ_Flat(void);

#ifdef  MODEL_ARA5040
extern unsigned char TUNER_BandChange_BandType(unsigned char ucDes,UI_TUNER_BAND ucBand);
extern void TUNER_LoadLastBand(unsigned char ucBand);
#endif
extern unsigned char TUNER_CallPresetFrequency(unsigned char ucNum);
extern void TUNER_FrequencyChange(unsigned char ucDes);
extern unsigned char TUNER_SavePresetFrequency(unsigned char ucNum);
extern unsigned char TUNER_SeekStart(unsigned char ucDes);
extern void TUNER_SetScan(void);
extern unsigned char TUNER_SetAutoStore(void);
extern UI_TUNER_MODE	ucTuner_Mode;
extern unsigned char 	ucTuner_ModeSeq;
extern unsigned char TUNER_ClearTunerMode(void);
extern void TUNER_BandChange(void);
extern void TUNER_PresetInitialize(void);

extern unsigned char	ucUSB_Pause;
extern unsigned char USB_SetPausePlay(void);

extern void USB_SetRepeat(void);
extern void USB_SetRandom(void);
extern void USB_SetInfo(unsigned char ucMode);
extern void USB_FolderChange(unsigned char ucDes);
extern unsigned char USB_FileChange(unsigned char ucDes);
#ifdef  FILE_SEARCH
extern unsigned char USB_FileSearch(unsigned char ucMode, unsigned char ucDir);
extern void USB_FileSearchPlay(void);
#endif
extern void USB_SetScan(void);
extern unsigned char ucUSB_ErrorCode;

#ifdef  CD
extern unsigned char	ucCD_Pause;
extern unsigned char	ucCD_ErrorCode;

#ifdef  FILE_SEARCH
extern unsigned char CD_FileSearch(unsigned char ucMode, unsigned char ucDir);
extern void CD_FileSearchPlay(void);
#endif

extern void CD_SetRandom(void);
extern void CD_SetRepeat(void);
extern void CD_SetInfo(unsigned char ucMode);
extern unsigned char CD_FolderChange(unsigned char ucDes);
extern unsigned char CD_FileChange(unsigned char ucDes);
extern unsigned char CD_SetPausePlay(void);
extern void CD_SetEject(unsigned char ucDes);
extern void CD_SetScan(void);
extern void CD_FastBackwardStart(void);
#endif

extern unsigned char DISP_BluetoothTestMode(void);
extern void DISP_SetCurrentDisplay(void);
extern void DISP_ClearTempDisplayMode(void);
extern void DISP_ClockDisplayModeCtrl(void);
extern unsigned char ucDISP_RadioInfo_Active;

extern UI_LOCAL ucUI_OPT_Local;

unsigned char MENU_KeyMain(KEY_ID ucKey, unsigned char ucLong);
extern void MENU_Clear(void);
extern void MENU_SetID(UI_MENU_ID ucID);
unsigned char ucBTSet;
#ifdef  BLUETOOTH
extern unsigned char BT_Key_Main(KEY_ID ucKey, unsigned char ucLongKey);
extern void BT_BluetoothVolume(unsigned char ucDes, unsigned char ucOption);
extern BT_PROC ucBT_Process;
extern void BT_CallTransfer(void);
#ifdef  MOVON
extern void MV_TX_SYS_StartSpkMicLoopBack(void);
#endif
#endif
#ifdef  LC786XXX
extern unsigned char	ucLC786XXX_InitializeComplete;
extern unsigned char DRV_LC786XXX_Stop(unsigned char ucMediaID, unsigned char ucMode);
extern void LC786XXX_ClearNameDisplayTimer(void);

#ifdef  LC786_SLEEP_TEST

extern unsigned char LC786XXX_GoToSleepOptional(unsigned char ucDes);

#endif

#endif

extern void CPU_ADC_GetValue(void);
extern UI_DISP ucDISP_TempDispMode;
extern unsigned short usCPU_ADC_Rmc;

#ifdef  ATOMIC
extern void ATOMIC_FM_SetSignalStopLevel(unsigned char ucUp);
extern void ATOMIC_AM_SetSignalStopLevel(unsigned char ucUp);
#endif
#ifdef  HERO
extern void HERO_FM_SetSignalStopLevel(unsigned char ucUp);
extern void HERO_AM_SetSignalStopLevel(unsigned char ucUp);
#endif

extern void OPT_WriteOptionMemory(void);

#ifdef BLUETOOTH
unsigned char KEY_GetBTPairingInvalid(unsigned char ucKey, unsigned char ucLongKey)
{
	unsigned char ucRet = 0;
	
	if  (BT_PRS_PAIRING == ucBT_Process)
	{
		switch  (ucKey)
		{
			case KEY_HANG_UP:
			case KEY_EJECT:	
			case KEY_POWER:	
			case KEY_NUM1:
			case KEY_NUM2:	
			case KEY_NUM3:
			case KEY_NUM4:	
			case KEY_NUM5:
			case KEY_NUM6:	
			case KEY_TUNE_UP:
			case KEY_TUNE_DOWN:	
			case KEY_VOL_UP:
			case KEY_VOL_DOWN:
			case KEY_RMC_MODE:
				ucRet = 1;
				break;
			case KEY_MENU:
				if  (MENU_GetID() <  MENU_BT_PAIR_ID)
				{
					ucRet = 1;
				}
				break;
		}		
	}
	else
	{
		ucRet = 1;
	}
	
	return(ucRet);
}
#endif

unsigned char KEY_TelMute_Valid(KEY_ID  ucKey)
{
	unsigned char ucRet = 1;

	switch  (ucKey)
	{
		case KEY_POWER:
			break;
		default:
			if  (ucAUDIO_TelMute == 1)
			{
				ucRet = 0;
			}
			break;
	}

	return(ucRet);
}

unsigned char KEY_Invalid(void)
{
	unsigned char ucRet = 0;
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			if  (ucTuner_Mode == TUNER_SEEK)
			{
				ucRet = 1;
			}
			if  (ucTuner_Mode == TUNER_SCAN)
			{
				if  (ucTuner_ModeSeq != TUNER_SCAN_WAIT_5SEC)
				{
					ucRet = 1;
				}
			}
			if  (ucTuner_Mode == TUNER_AST)
			{
				if  (ucTuner_ModeSeq != TUNER_AST_DEMO_WAIT_5S)
				{
					ucRet = 1;
				}
			}
			break;
	#if 0
		case FUNC_USB:
			if  (LC786XXX_GetMediaStatus(FUNC_USB) != LC786X_MS_PLAYBACK)
			{
				ucRet = 1;
			}
			break;
	#ifdef  CD
		case FUNC_CD:
			if  (LC786XXX_GetMediaStatus(FUNC_CD) != LC786X_MS_PLAYBACK)
			{
				ucRet = 1;
			}
			break;
	#endif
	#endif 
	}
	return(ucRet);
}

void KEY_Short_Power(void)
{
	if  (MENU_KeyMain(KEY_POWER, 0) == 1)	// Select of Menu
	{
		return;
	}
	if  (ucFUNC_Power == 0)	// Power On
	{	
		FUNC_PowerOn();
	}
	else
	{	// Mute
		if  (FUNC_FunctionChangeStatus() == 1)
		{
			return;
		}
		switch  (ucFUNC_Current)
		{
			case FUNC_TUNER:
				if  (TUNER_SoundStatus() == 0)
				{
					return;
				}
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetBlink();
				DISP_SetCurrentDisplay();
				AUDIO_SetMute(2);// Mute toggle
				break;
			case FUNC_USB:
				if  ((ucUSB_Pause == 0) && (USB_SoundStatus() == 1))
				{
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					DISP_SetBlink();
					DISP_SetCurrentDisplay();
					AUDIO_SetMute(2);// Mute toggle
				}
				break;
			case FUNC_AUX:
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetBlink();
				DISP_SetCurrentDisplay();
				AUDIO_SetMute(2);// Mute toggle
				break;	
		#ifdef  CD
			case FUNC_CD:
				if  ((ucCD_Pause == 0) && (CD_SoundStatus() == 1))
				{
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					DISP_SetBlink();
					DISP_SetCurrentDisplay();
					AUDIO_SetMute(2);// Mute toggle
				}
				break;
		#endif
		#ifdef  BLUETOOTH
			case FUNC_A2DP:
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetBlink();
				DISP_SetCurrentDisplay();
				AUDIO_SetMute(2);// Mute toggle
				break;
			case FUNC_HF:
				BT_Key_Main(KEY_POWER, 0);
	//				DISP_ClearTempDisplayMode();
	//				DISP_SetCurrentDisplay();
				break;
		#endif
		}	
	}
}

void KEY_Long_Power(void)
{
	if  (ucFUNC_Power == 0)
	{
		LOG_KEY("<<Power On Long>>");
		FUNC_PowerOn();
		return;
	}
	//AUDIO_BeepOutStart();
	DISP_ClearTempDisplayMode();
	MENU_Clear();
	DISP_SetCurrentDisplay();
	FUNC_PowerOff();
	AUDIO_SetMute(3);
#ifdef BLUETOOTH
	BT_CallTransfer();
#endif
#ifdef  MIC
	if  (MIC_GetHostMicStatus() == MIC_ON)
	{
		MIC_SetHostMicStatus(MIC_OFF);
		MIC_SetMicStatus(MIC_OFF);
		MIC_SetMixMode(MIX_OFF);
	#ifdef  AUTO_GUIDE
		AG_ProcessStop();
	#endif
	#ifdef  AV_CONTROLLER
		AVC_ProcessStop();
	#endif
	}
#endif
}

void KEY_Short_USB(void)
{
	if  (ucLC786XXX_InitializeComplete == 0)
	{
		return;
	}
	if  ((FUNC_PowerStatus() == 1) && (FUNC_GetCurrentFunction() == FUNC_USB))
	{
		return;
	}
#ifdef  BLUETOOTH
	if  (FUNC_GetCurrentFunction() == FUNC_HF)
	{
		return;
	}
#endif
	
#ifdef  MIC
	if  (MIC_GetHostMicStatus() == MIC_ON)
	{
		MIC_SetHostMicStatus(MIC_OFF);
	}
#endif
	DISP_ClearTempDisplayMode();
	MENU_Clear();
	DISP_SetCurrentDisplay();
	if  (FUNC_SelectUSB() == 0)
	{
		if  (ucUSB_ErrorCode != LC786X_EC_NoError)
		{
			switch (ucUSB_ErrorCode)
			{
				case LC786X_EC_NoFile:
					DISP_SetTempDisplayMode(DISP_NO_FILE);
					break;
				case LC786X_EC_PUIN_SW_ON_Error: 	
				case LC786X_EC_PUIN_SW_OFF_Error: 	
				case LC786X_EC_USB_EnumerateError: 
				case LC786X_EC_USB_ErrResponse: 	
				case LC786X_EC_FileSysUnknown: 		
				case LC786X_EC_FileSysAnalyze: 		
					DISP_SetTempDisplayMode(DISP_USB_ERROR);
					break;
				case LC786X_EC_USB_ErrDriver:
					DISP_SetTempDisplayMode(DISP_USB_DEVICE_ERROR);
					break;	
			}
		}
		else
		{
			DISP_SetTempDisplayMode(DISP_NO_USB);// No Function
		}
		if  (ucFUNC_Power == 1)
		{
			AUDIO_SetMute(0);
		}
	}
		
}

#ifdef  CD
void KEY_Short_CD(void)
{
#ifdef  BLUETOOTH
	if  (FUNC_GetCurrentFunction() == FUNC_HF)
	{
		return;
	}
#endif
	if  (ucLC786XXX_InitializeComplete == 0)
	{
		return;
	}
	if  ((FUNC_PowerStatus() == 1) && (FUNC_GetCurrentFunction() == FUNC_CD))
	{
		return;
	}
	if  (DECK_CurrentMode_Eject() == 1)
	{
		return;
	}
	DISP_ClearTempDisplayMode();
	MENU_Clear();
	DISP_SetCurrentDisplay();
#ifdef  MIC
	if  (MIC_GetHostMicStatus() == MIC_ON)
	{
		MIC_SetHostMicStatus(MIC_OFF);
	}
#endif
	
	if  (FUNC_SelectCD() == 0)
	{
		if  (ucCD_ErrorCode != LC786X_EC_NoError)
		{
			switch (ucCD_ErrorCode)
			{
				case LC786X_EC_NoFile:
					DISP_SetTempDisplayMode(DISP_NO_FILE);
					break;
				case LC786X_EC_PUIN_SW_ON_Error: 	
				case LC786X_EC_PUIN_SW_OFF_Error: 	
				case LC786X_EC_USB_EnumerateError: 
				case LC786X_EC_USB_ErrResponse: 	
				case LC786X_EC_FileSysUnknown: 		
				case LC786X_EC_FileSysAnalyze:
				case LC786X_EC_AutoAdjustError:
					DISP_SetTempDisplayMode(DISP_CD_ERROR);
					break;
				case LC786X_EC_USB_ErrDriver:
					DISP_SetTempDisplayMode(DISP_USB_DEVICE_ERROR);
					break;	
			}
		}
		else
		{	
			DISP_SetTempDisplayMode(DISP_NO_CD);// No Function
		}
		if  (ucFUNC_Power == 0)
		{	
			return;
		}
		else
		{
			AUDIO_SetMute(0);
			return;
		}
	}
}
#endif

void KEY_Short_Mode(void)
{
#ifdef  BLUETOOTH
	if  (FUNC_GetCurrentFunction() == FUNC_HF)
	{
		return;
	}
#endif
#ifdef  LC786XXX
	if  (ucLC786XXX_InitializeComplete == 0)
	{
		return;
	}
#endif
	DISP_ClearTempDisplayMode();
	MENU_Clear();
#ifdef  MIC
	if  (MIC_GetHostMicStatus() == MIC_ON)
	{
		MIC_SetHostMicStatus(MIC_OFF);
	}
#endif
	if  (ucFUNC_Power == 0)
	{
		if  ((FUNC_GetCurrentFunction() == FUNC_TUNER) || (FUNC_GetCurrentFunction() == FUNC_AVC_MODE))
		{
			if  (FUNC_MediaChange() == 0)
	 		{
				DISP_SetTempDisplayMode(DISP_NO_MECH);
				AUDIO_SetMute(3);
			}
		}
		else
		{
			if  (FUNC_CheckFunctionAvailable(ucFUNC_Current) == 1)
			{
				FUNC_FunctionChangeStart(ucFUNC_Current,FUNC_POWER_ON_SEQ0);
			}
			else
			{
				FUNC_FunctionChangeStart(FUNC_GetPreviousMedia(), FUNC_POWER_ON_SEQ0);
			}
		}
	}
	else
	{
		if  (FUNC_MediaChange() == 0)
	 	{
			DISP_SetTempDisplayMode(DISP_NO_MECH);
			AUDIO_SetMute(3);
		}
	}
}

void KEY_Short_Mode_TotalFunction(void)
{
#ifdef  BLUETOOTH
	if  (FUNC_GetCurrentFunction() == FUNC_HF)
	{
		return;
	}
#endif
#ifdef  LC786XXX
	if  (ucLC786XXX_InitializeComplete == 0)
	{
		return;
	}
#endif
#ifdef  MIC
	if  (MIC_GetHostMicStatus() == MIC_ON)
	{
		MIC_SetHostMicStatus(MIC_OFF);
	}
#endif
	if  (ucFUNC_Power == 1)
	{
		DISP_ClearTempDisplayMode();
		MENU_Clear();
		FUNC_TotalFunctionChange();
		AUDIO_SetMute(3);
	}
	else
	{
		FUNC_PowerOn();
	}
}

void KEY_Short_AUX(void)
{
#ifdef  BLUETOOTH
	if  (FUNC_GetCurrentFunction() == FUNC_HF)
	{
		return;
	}
#endif
	if  ((FUNC_PowerStatus() == 1) && (FUNC_GetCurrentFunction() == FUNC_AUX))
	{
		return;
	}
	DISP_ClearTempDisplayMode();
	MENU_Clear();
	DISP_SetCurrentDisplay();
#ifdef  MIC
	if  (MIC_GetHostMicStatus() == MIC_ON)
	{
		MIC_SetHostMicStatus(MIC_OFF);
	}
#endif
	
	if  (FUNC_SelectAux() == 0)
	{	
		DISP_SetTempDisplayMode(DISP_NO_AUX);// No Function
		if  (ucFUNC_Power == 0)
		{	
			return;
		}
		else
		{
			AUDIO_SetMute(0);
			return;
		}
	}

	#if 0
	if  (FUNC_SelectAux() == 0)
	{
		DISP_SetTempDisplayMode(DISP_NO_AUX);// No Function
		DISP_SetBlink();
		//AUDIO_SetMute(0);
	}	
	#endif
	
}

#ifdef  MODEL_ARA5040
void KEY_Short_Loud(void)
{
	if  (ucFUNC_Power == 1)
	{
		switch  (FUNC_GetCurrentFunction())
		{
			case FUNC_TUNER:
				if  (TUNER_SoundStatus() == 0)
				{
					return;
				}
				break;
			case FUNC_USB:
				if	(USB_SoundStatus() == 0)
				{
					return;
				}
			
				if  (ucUSB_Pause == 1)
				{
					return;
				}
				break;
		#ifdef  CD
			case FUNC_CD:
				if	(CD_SoundStatus() == 0)
				{
					return;
				}
			
				if  (ucCD_Pause == 1)
				{
					return;
				}
				break;
		#endif
		}
		AUDIO_SetMute(0);
		AUDIO_ChangeLoud();
	}
}
void KEY_Short_Band(UI_TUNER_BAND ucBand)
{
	unsigned char ucDes;
	
#ifdef  BLUETOOTH
		if	(FUNC_GetCurrentFunction() == FUNC_HF)
		{
			return;
		}
#endif

	DISP_ClearTempDisplayMode();
	MENU_Clear();
	DISP_SetCurrentDisplay();
	if  (ucFUNC_Power == 0)
	{
		if  (TUNER_CurrentBandType() == ucBand)
		{
		}
		else
		{
			TUNER_LoadLastBand(ucBand);
		}
		DISP_ClearTempDisplayMode();
		MENU_Clear();
		FUNC_FunctionChangeStart(FUNC_TUNER,FUNC_POWER_ON_SEQ0);
		return;		
	}
	
	AUDIO_SetMute(0);
	
	if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
	{
		ucDes = TUNER_BandChange_BandType(1, ucBand);
	}
	else
	{
		ucDes = TUNER_BandChange_BandType(0, ucBand);
		FUNC_FunctionChangeStart(FUNC_TUNER,FUNC_CHANGE_SEQ0);
	}
	
//	if  ((ucDes == 1) || (FUNC_GetCurrentFunction() != FUNC_TUNER))
//	{
//		FUNC_FunctionChangeStart(FUNC_TUNER,FUNC_CHANGE_SEQ0);
//	}

	if  (ucDes == 0)
	{
		DISP_SetCurrentDisplay();
	}
}

#else

void KEY_Short_Band(void)
{
#ifdef  BLUETOOTH
	if  (FUNC_GetCurrentFunction() == FUNC_HF)
	{
		return;
	}
#endif
	DISP_ClearTempDisplayMode();
	MENU_Clear();
#ifdef  MIC
	if  (MIC_GetHostMicStatus() == MIC_ON)
	{
		MIC_SetHostMicStatus(MIC_OFF);
	}
#endif
	DISP_SetCurrentDisplay();
	if  (ucFUNC_Power == 0)
	{
		DISP_ClearTempDisplayMode();
		MENU_Clear();
		FUNC_FunctionChangeStart(FUNC_TUNER,FUNC_POWER_ON_SEQ0);
		return;
	}
#ifdef  AUTO_GUIDE
	if	(AG_GetAnnounceStatus() == AG_ANNOUNCE_OFF)
#endif
	{
		AUDIO_SetMute(3);
	}
	if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
	{
		TUNER_BandChange();
		DISP_SetCurrentDisplay();
	}
	else
	{
		DISP_ClearTempDisplayMode();
		MENU_Clear();
		FUNC_FunctionChangeStart(FUNC_TUNER,FUNC_CHANGE_SEQ0);
	}
}

#endif

#ifdef  MIC
void KEY_Short_MIC(void)
{
#ifdef  BLUETOOTH
	if  (FUNC_GetCurrentFunction() == FUNC_HF)
	{
		return;
	}
#endif
	AUDIO_SetMute(0);
	DISP_ClearTempDisplayMode();
	MENU_Clear();
	DISP_SetCurrentDisplay();

	if  (MIC_GetHostMicStatus() == MIC_OFF)
	{
		if  (FUNC_PowerStatus() == 1)
		{
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				TUNER_ClearTunerMode();
			}
		}
		else
		{
			FUNC_FunctionChangeStart(FUNC_GetCurrentFunction(),FUNC_POWER_ON_SEQ0);
		}
		MIC_SetHostMicStatus(MIC_ON);
//		if  (MIC_GetMicStatus() == MIC_OFF)
//		{
//			MIC_SetMicStatus(MIC_ON);
//			MIC_SetMixMode(MIX_OFF);
//		}
	}
	else
	{
		MIC_SetHostMicStatus(MIC_OFF);
//		if  (MIC_GetMicStatus() == MIC_ON)
//		{
//			MIC_SetMicStatus(MIC_OFF);
//			MIC_SetMixMode(MIX_OFF);
//			AUDIO_InputSelect(FUNC_GetCurrentFunction());
//		}
	}
}

#endif

void KEY_Short_Menu(void)
{
	if  (ucFUNC_Power == 1)
	{
		switch  (FUNC_GetCurrentFunction())
		{
			case FUNC_TUNER:
				if  (TUNER_SoundStatus() == 0)
				{
					return;
				}
				MENU_KeyMain(KEY_MENU, 0);
				break;
			#ifdef CD
			case FUNC_CD:
				if	(CD_SoundStatus() == 0)
				{
					return;
				}
			
				if  (ucCD_Pause == 0)
				{
					MENU_KeyMain(KEY_MENU, 0);
					AUDIO_SetMute(0);
				}
				break;
			#endif	
			case FUNC_USB:
				if	(USB_SoundStatus() == 0)
				{
					return;
				}
			
				if  (ucUSB_Pause == 0)
				{
					MENU_KeyMain(KEY_MENU, 0);
					AUDIO_SetMute(0);
				}
				break;
		#ifdef  BLUETOOTH
			case FUNC_HF:
				break;
		#endif
			default:
				MENU_KeyMain(KEY_MENU, 0);
				AUDIO_SetMute(0);
				break;
		}
	}
	else 
	{
		if  ((ucMenuID == MENU_CLOCK_SET_HOUR_ID) || (ucMenuID == MENU_CLOCK_SET_MIN_ID))
		{
			MENU_KeyMain(KEY_MENU, 0);
		}
	}
}	
	
void KEY_Long_Menu(void)
{
	if  (ucFUNC_Power == 1)
	{
		switch  (FUNC_GetCurrentFunction())
		{
			case FUNC_TUNER:
				if  (TUNER_SoundStatus() == 1)
				{
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					DISP_SetCurrentDisplay();
					DISP_ClockDisplayModeCtrl();
					AUDIO_SetMute(0);
					AUDIO_BeepOutStart();
				}
				else
				{
					KEY_Short_Menu();
				}
				break;
			#ifdef  CD
			case FUNC_CD:
				if  (ucCD_Pause == 0)
				{
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					DISP_SetCurrentDisplay();
					DISP_ClockDisplayModeCtrl();
					AUDIO_SetMute(0);
					AUDIO_BeepOutStart();
				}
				break;
			#endif
			case FUNC_USB:
				if  (ucUSB_Pause == 0)
				{
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					DISP_SetCurrentDisplay();
					DISP_ClockDisplayModeCtrl();
					AUDIO_SetMute(0);
					AUDIO_BeepOutStart();
				}
				break;
		#ifdef  BLUETOOTH
			case FUNC_HF:
				break;
		#endif
			default:
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				DISP_ClockDisplayModeCtrl();
				AUDIO_SetMute(0);
				AUDIO_BeepOutStart();
				break;
		}
	}
	else
	{
		MENU_KeyMain(KEY_MENU, 1);
	}
}

void KEY_Short_Num1_Pause(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
#ifdef  BLUETOOTH
	if  (DISP_BluetoothTestMode() == 1)
	{		
		DISP_SetTempDisplayMode_6Sec(DISP_BT_ADD1);
		BT_FunctionStop();
		BT_SetDBAddress(BT_DB_ADR_01);
		BT_InitializeStart();
		return;
	}
#endif
	DISP_SetBlink();

	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
		#ifdef  LC786_SLEEP_TEST
			if  (LC786XXX_GoToSleepOptional(0x00) == 1)
			{
				return;
			}
		#endif
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if  (TUNER_CallPresetFrequency(1) == 1)
			{
				AUDIO_SetMute(3);
			}
			else
			{
				AUDIO_SetMute(0);
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
			if  (ucAUDIO_Mute == 0)
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				if  (USB_SetPausePlay() == 1)
				{
				}
				else
				{
			//		AUDIO_SetMute(0);
				}
			}
			else
			{
				USB_SetPausePlay();
				AUDIO_SetMute(0);
			}
			break;
		#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
			if  (ucAUDIO_Mute == 0)
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				if  (CD_SetPausePlay() == 1)
				{
				}
				else
				{
			//		AUDIO_SetMute(0);
				}
			}
			else
			{
				CD_SetPausePlay();
				AUDIO_SetMute(0);
			}
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			BT_Key_Main(KEY_NUM1, 0);
			break;
		#endif
		default:
			//DISP_ClearTempDisplayMode();
			//MENU_Clear();
			//DISP_SetCurrentDisplay();
			break;
	}
}

void KEY_Long_Num1_Pause(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			if  ((ucAUDIO_Mute == 0) && (TUNER_SavePresetFrequency(1) == 1))
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				AUDIO_BeepOutStart();
				AUDIO_SetMute(0);
			}
			else
			{
				KEY_Short_Num1_Pause();
			}
			break;
		case FUNC_USB:
			KEY_Short_Num1_Pause();
			break;
		#ifdef  CD
		case FUNC_CD:
			KEY_Short_Num1_Pause();
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			KEY_Short_Num1_Pause();
			break;
		#endif
		default:
			break;
	}
}

void KEY_Short_Num2_Repeat(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
#ifdef  BLUETOOTH
	if  (DISP_BluetoothTestMode() == 1)
	{		
		DISP_SetTempDisplayMode_6Sec(DISP_BT_ADD2);
		BT_FunctionStop();
		BT_InitializeStart();
		BT_SetDBAddress(BT_DB_ADR_01);
		return;
	}
#endif
	LOG_KEY("KEY_Short_Num2_Repeat");
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
		#ifdef  LC786_SLEEP_TEST
			if  (LC786XXX_GoToSleepOptional(0x01) == 1)
			{
				return;
			}
		#endif
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if  (TUNER_CallPresetFrequency(2) == 1)
			{
				AUDIO_SetMute(3);
			}
			else
			{
				AUDIO_SetMute(0);
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			USB_SetRepeat();
			AUDIO_SetMute(0);
			break;
		#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
			LOG_KEY("CD");
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			CD_SetRepeat();
			AUDIO_SetMute(0);
			break;
		#endif
		default:
			break;
	}
}

void KEY_Long_Num2_Repeat(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			if  ((ucAUDIO_Mute == 0) && (TUNER_SavePresetFrequency(2) == 1))
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				AUDIO_BeepOutStart();
				AUDIO_SetMute(0);
			}
			else
			{
				KEY_Short_Num2_Repeat();
			}
			break;
		case FUNC_USB:
			KEY_Short_Num2_Repeat();
			break;
		#ifdef  CD
		case FUNC_CD:
			KEY_Short_Num2_Repeat();
			break;
		#endif
		default:
			break;
	}
}

void KEY_Short_Num3_Random(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
#ifdef  BLUETOOTH
	if  (DISP_BluetoothTestMode() == 1)
	{		
		DISP_SetTempDisplayMode_6Sec(DISP_BT_DUT);
		MV_TX_SYS_Enter_DUT_Mode();
		return;
	}
#endif
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
		#ifdef  LC786_SLEEP_TEST
			if  (LC786XXX_GoToSleepOptional(0x02) == 1)
			{
				return;
			}
		#endif
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if  (TUNER_CallPresetFrequency(3) == 1)
			{
				AUDIO_SetMute(3);
			}
			else
			{
				AUDIO_SetMute(0);
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			USB_SetRandom();
			AUDIO_SetMute(0);
			break;
		#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			CD_SetRandom();
			AUDIO_SetMute(0);
			break;
		#endif
			break;
	}
}

void KEY_Long_Num3_Random(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			if  ((ucAUDIO_Mute == 0) && (TUNER_SavePresetFrequency(3) == 1))
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				AUDIO_BeepOutStart();
				AUDIO_SetMute(0);
			}
			else
			{
				KEY_Short_Num3_Random();
			}
			break;
		case FUNC_USB:
			KEY_Short_Num3_Random();
			break;
		#ifdef  CD
		case FUNC_CD:
			KEY_Short_Num3_Random();
			break;
		#endif
		default:
			break;
	}
}

void KEY_Short_Num4_Info(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if  (TUNER_CallPresetFrequency(4) == 1)
			{
				AUDIO_SetMute(3);
			}
			else
			{
				AUDIO_SetMute(0);
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			LC786XXX_ClearNameDisplayTimer();
			USB_SetInfo(0);
			AUDIO_SetMute(0);
			break;
		#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			LC786XXX_ClearNameDisplayTimer();
			CD_SetInfo(0);
			AUDIO_SetMute(0);
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			if  (ucDISP_TempDispMode == DISP_BT_CONNECT_DEVICE_NAME)
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
			}
			else
			{
				DISP_SetCurrentDisplay();
				AUDIO_SetMute(0);
				DISP_SetTempDisplayMode(DISP_BT_CONNECT_DEVICE_NAME);
			}
			//BT Connect device Name Display
			break;
		#endif
		default:
			break;
	}
}

void KEY_Long_Num4_Info(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			if  ((ucAUDIO_Mute == 0) && (TUNER_SavePresetFrequency(4) == 1))
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				AUDIO_BeepOutStart();
				AUDIO_SetMute(0);
			}
			else
			{
				KEY_Short_Num4_Info();
			}
			break;
		case FUNC_USB:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			LC786XXX_ClearNameDisplayTimer();
			DISP_SetCurrentDisplay();
			USB_SetInfo(1);
			AUDIO_BeepOutStart();
			AUDIO_SetMute(0);
			break;
		#ifdef  CD
		case FUNC_CD:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			LC786XXX_ClearNameDisplayTimer();
			CD_SetInfo(1);
			AUDIO_BeepOutStart();
			AUDIO_SetMute(0);
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			KEY_Short_Num4_Info();
			break;
		#endif
		default:
			break;
	}
}

void KEY_Short_Num5_DirDown(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if  (TUNER_CallPresetFrequency(5) == 1)
			{
				AUDIO_SetMute(3);
			}
			else
			{
				AUDIO_SetMute(0);
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
		//	DISP_ClearTempDisplayMode();
		//	MENU_Clear();
		//	DISP_SetCurrentDisplay();         //move to LC786XXX_MediaStatusCheck_USB
			USB_FolderChange(0);
			AUDIO_SetMute(3);
			break;
		#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
			if  (CD_FolderChange(0) == 1)
			{
		//		DISP_ClearTempDisplayMode();
		//		MENU_Clear();
		//		DISP_SetCurrentDisplay();
				AUDIO_SetMute(3);
			}
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			break;
		#endif
		default:
			break;
	}
}

void KEY_Long_Num5_DirDown(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			if  ((ucAUDIO_Mute == 0) && (TUNER_SavePresetFrequency(5) == 1))
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				AUDIO_BeepOutStart();
				AUDIO_SetMute(0);
			}
			else
			{
				KEY_Short_Num5_DirDown();
			}
			break;
		case FUNC_USB:
			KEY_Short_Num5_DirDown();
			break;
		#ifdef  CD
		case FUNC_CD:
			KEY_Short_Num5_DirDown();
			break;
		#endif
		default:
			break;
	}
}

void KEY_Short_Num6_DirUp(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if  (TUNER_CallPresetFrequency(6) == 1)
			{
				AUDIO_SetMute(3);
			}
			else
			{
				AUDIO_SetMute(0);
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
	//		DISP_ClearTempDisplayMode();
	//		MENU_Clear();
	//		DISP_SetCurrentDisplay();       //move to LC786XXX_MediaStatusCheck_USB
			USB_FolderChange(1);
			AUDIO_SetMute(3);
			break;
		#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
			if  (CD_FolderChange(1) == 1)
			{
		//		DISP_ClearTempDisplayMode();
		//		MENU_Clear();
		//		DISP_SetCurrentDisplay();
				AUDIO_SetMute(3);
			}
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			break;
		#endif
		default:
			break;
	}
}

void KEY_Long_Num6_DirUp(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			if  ((ucAUDIO_Mute == 0) && (TUNER_SavePresetFrequency(6) == 1))
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				AUDIO_BeepOutStart();
				AUDIO_SetMute(0);
			}
			else
			{
				KEY_Short_Num6_DirUp();
			}
			break;
		case FUNC_USB:
			KEY_Short_Num6_DirUp();
			break;
		#ifdef  CD
		case FUNC_CD:
			KEY_Short_Num6_DirUp();
			break;
		#endif
		default:
			break;
	}
}

void KEY_Long_SearchRelease(void)
{
	if	(ucFUNC_Power == 0)
	{
		return;
	}
		
	switch	(FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			break;
		case FUNC_USB:
			USB_FFREW_Release();
			break;
	#ifdef  CD
		case FUNC_CD:
			CD_FFREW_Release();
			break;
	#endif
	#ifdef  BLUETOOTH
		case FUNC_A2DP:
			break;
	#endif
		default:
			break;
	}
}

void KEY_Long_SearchUp(void)
{
	if	(ucFUNC_Power == 0)
	{
		return;
	}
		
	switch	(FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if  (TUNER_SeekStart(1) == 1)
			{
				AUDIO_SetMute(3);
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			USB_FastForwardStart();
			AUDIO_SetMute(0);
			break;
	#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			CD_FastForwardStart();
			AUDIO_SetMute(0);
			break;
	#endif
	#ifdef  BLUETOOTH
		case FUNC_A2DP:
			BT_Key_Main(KEY_TUNE_UP, 1);
			DISP_SetTempDisplayMode(DISP_BT_FWD);
			break;
	#endif
		default:
			break;
	}

}

void KEY_Short_SeekUP(void)
{	
	if	(ucFUNC_Power == 0)
	{
		return;
	}
	
	switch	(FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if	(TUNER_SeekStart(1) == 1)
			{
				AUDIO_SetMute(3);
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
		
			USB_FileChange(1);
			AUDIO_SetMute(3);
			break;
#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
		
			CD_FileChange(1);
			AUDIO_SetMute(3);
			break;
#endif
#ifdef  BLUETOOTH
		case FUNC_A2DP:
			BT_Key_Main(KEY_TUNE_UP, 0);
			DISP_SetTempDisplayMode(DISP_BT_RWD);
			break;
#endif
		default:
			break;
	}

}

void KEY_Short_TuneDown(void)
{	
	if	(ucFUNC_Power == 0)
	{
		return;
	}
	
	switch	(FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if	(TUNER_SeekStart(0) == 1)
			{
				AUDIO_SetMute(3);
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
		
			if  (USB_FileChange(0) == 0)
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
			}
			AUDIO_SetMute(3);
			break;
#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
		
			if  (CD_FileChange(0) == 0)
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
			}
			AUDIO_SetMute(3);
			break;
#endif
#ifdef  BLUETOOTH
		case FUNC_A2DP:
			BT_Key_Main(KEY_TUNE_DOWN, 0);
			DISP_SetTempDisplayMode(DISP_BT_RWD);
			break;
#endif
		default:
			break;
	}

}


void KEY_Long_SearchDown(void)
{
	if	(ucFUNC_Power == 0)
	{
		return;
	}
	
	switch	(FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			if  (TUNER_SeekStart(0) == 1)
			{
				AUDIO_SetMute(3);				
				AUDIO_BeepOutStart();
			}
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			USB_FastBackwardStart();
			AUDIO_SetMute(0);
			break;
	#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			CD_FastBackwardStart();
			AUDIO_SetMute(0);
			break;
	#endif
	#ifdef  BLUETOOTH
		case FUNC_A2DP:
			BT_Key_Main(KEY_TUNE_DOWN, 1);
			DISP_SetTempDisplayMode(DISP_BT_RWD);
			break;
	#endif
		default:
			break;
	}

}
#ifdef  ST_EV_ADJ

extern void ST7565_SendCommand(unsigned char ucDes);	// Set Electronic Volume Level
extern unsigned char ucST7565_EV_Level;

#endif

void KEY_Short_TuneUp_RMC(void)	
{
	if	(ucFUNC_Power == 0)
	{
		return;
	}

#ifdef  ST_EV_ADJ
	DISP_SetTempDisplayMode_3Sec(DISP_ST_EV);

	if	(++ucST7565_EV_Level > 0x3F)
	{
		ucST7565_EV_Level = 0x3F;
	}
#else
	switch	(FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			TUNER_PresetFrequency_Up();
			AUDIO_SetMute(3);
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
		//	DISP_SetCurrentDisplay();
			USB_FileChange(1);
			AUDIO_SetMute(3);
			break;
	#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
		//	DISP_SetCurrentDisplay();
			CD_FileChange(1);
			AUDIO_SetMute(3);
			break;
	#endif
	#ifdef  BLUETOOTH
		case FUNC_A2DP:
			BT_Key_Main(KEY_TUNE_UP, 0);
			DISP_SetTempDisplayMode(DISP_BT_FWD);
		//	AUDIO_SetMute(0);
			break;
	#endif
		default:
			break;
	}
#endif
}

extern unsigned char ucBT_MIC_Volume;
extern void MV_TX_HF_WriteMICVolume_Req(unsigned char ucVolume);

void KEY_Short_SearchUp(void)
{
#ifdef  MODEL_AGC505X
	if  (MENU_KeyMain(KEY_VOL_UP, 0) == 1)
	{
		return;
	}
#endif
	if  (ucDISP_RadioInfo_Active != 0)
	{
		if  (ucDISP_RadioInfo_Active == 0x01)
		{
			ucDISP_RadioInfo_Active = 0x02;
		}
		else
		{
			ucDISP_RadioInfo_Active = 0x01;
		}
		return;
	}
	if  (ucDISP_TempDispMode == DISP_TUNER_SEEK_TEST)
	{
		DISP_SetTempDisplayMode_6Sec(DISP_TUNER_SEEK_TEST);
	#ifdef  ATOMIC
		if  (TUNER_CurrentBandType() == FM)
		{
			ATOMIC_FM_SetSignalStopLevel(1);
		}
		else
		{
			ATOMIC_AM_SetSignalStopLevel(1);
		}
	#endif
	#ifdef  HERO
		if  (TUNER_CurrentBandType() == FM)
		{
			HERO_FM_SetSignalStopLevel(1);
		}
		else
		{
			HERO_AM_SetSignalStopLevel(1);
		}
	#endif
		return;
	}
	if  (ucFUNC_Power == 0)
	{
		return;
	}

#ifdef  ST_EV_ADJ
	DISP_SetTempDisplayMode_3Sec(DISP_ST_EV);

	if  (++ucST7565_EV_Level > 0x3F)
	{
		ucST7565_EV_Level = 0x3F;
	}
#else
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			TUNER_FrequencyChange(1);
			AUDIO_SetMute(3);
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
		
	//		DISP_SetCurrentDisplay();
		#ifdef  FILE_SEARCH
			if  (ucDISP_TempDispMode == DISP_FILE_SEARCH)
			{
				USB_FileSearch(1, 1);
			}
			else
			{
				USB_FileSearch(0, 1);
			}
			MENU_Clear();
			DISP_PageScrollReset();
			DISP_SetTempDisplayMode(DISP_FILE_SEARCH);
		#else
			USB_FileChange(1);
			AUDIO_SetMute(3);
		#endif
			break;
		#ifdef  CD
		case FUNC_CD:
		#ifdef CD
			if	(CD_SoundStatus() == 0)
			{
				return;
			}		
		#endif
		#ifdef  FILE_SEARCH
			if  (ucDISP_TempDispMode == DISP_FILE_SEARCH)
			{
				CD_FileSearch(1, 1);
			}
			else
			{
				CD_FileSearch(0, 1);
			}
			MENU_Clear();
			DISP_PageScrollReset();
			DISP_SetTempDisplayMode(DISP_FILE_SEARCH);
		#else
			CD_FileChange(1);
			AUDIO_SetMute(3);
		#endif
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			BT_Key_Main(KEY_TUNE_UP, 0);
			DISP_SetTempDisplayMode(DISP_BT_FWD);
		//	AUDIO_SetMute(0);
			break;
		case FUNC_LPB:
			if  (++ucBT_MIC_Volume > 15)
			{
				ucBT_MIC_Volume = 15;
			}
			MV_TX_HF_WriteMICVolume_Req(ucBT_MIC_Volume);
			DISP_SetTempDisplayMode(DISP_BT_MICVOLUME);
			//
			break;
		#endif
		default:
			break;
	}
#endif
}

void KEY_Short_SearchDown(void)
{
#ifdef  MODEL_AGC505X
	if  (MENU_KeyMain(KEY_VOL_DOWN, 0) == 1)
	{
		return;
	}
#endif
	if  (ucDISP_RadioInfo_Active != 0)
	{
		if  (ucDISP_RadioInfo_Active == 0x01)
		{
			ucDISP_RadioInfo_Active = 0x02;
		}
		else
		{
			ucDISP_RadioInfo_Active = 0x01;
		}
		return;
	}
	if  (ucDISP_TempDispMode == DISP_TUNER_SEEK_TEST)
	{
		DISP_SetTempDisplayMode_6Sec(DISP_TUNER_SEEK_TEST);
	#ifdef  ATOMIC
		if  (TUNER_CurrentBandType() == FM)
		{
			ATOMIC_FM_SetSignalStopLevel(0);
		}
		else
		{
			ATOMIC_AM_SetSignalStopLevel(0);
		}
	#endif
	#ifdef  HERO
		if  (TUNER_CurrentBandType() == FM)
		{
			HERO_FM_SetSignalStopLevel(0);
		}
		else
		{
			HERO_AM_SetSignalStopLevel(0);
		}
	#endif
		return;
	}
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
#ifdef  ST_EV_ADJ
	DISP_SetTempDisplayMode_3Sec(DISP_ST_EV);

	if  (ucST7565_EV_Level == 0)
	{
	}
	else
	{
		--ucST7565_EV_Level;
	}
#else
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			TUNER_FrequencyChange(0);
			AUDIO_SetMute(3);
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
	//		DISP_ClearTempDisplayMode();
	//		MENU_Clear();
	//		DISP_SetCurrentDisplay();
		#ifdef  FILE_SEARCH
			if  (ucDISP_TempDispMode == DISP_FILE_SEARCH)
			{
				USB_FileSearch(1, 0);
			}
			else
			{
				USB_FileSearch(0, 0);
			}
			MENU_Clear();
			DISP_PageScrollReset();
			DISP_SetTempDisplayMode(DISP_FILE_SEARCH);
		#else
			USB_FileChange(0);
			AUDIO_SetMute(0);
		#endif
			break;
		#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
	//		DISP_ClearTempDisplayMode();
	//		MENU_Clear();
	//		DISP_SetCurrentDisplay();
		#ifdef  FILE_SEARCH
			if  (ucDISP_TempDispMode == DISP_FILE_SEARCH)
			{
				CD_FileSearch(1, 0);
			}
			else
			{
				CD_FileSearch(0, 0);
			}
			MENU_Clear();
			DISP_PageScrollReset();
			DISP_SetTempDisplayMode(DISP_FILE_SEARCH);
		#else
			CD_FileChange(0);
			AUDIO_SetMute(0);
		#endif
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			BT_Key_Main(KEY_TUNE_DOWN, 0);	
			DISP_SetTempDisplayMode(DISP_BT_RWD);
			break;
		case FUNC_LPB:
			if  (ucBT_MIC_Volume == 0)
			{
			}
			else
			{
				--ucBT_MIC_Volume;
			}
			MV_TX_HF_WriteMICVolume_Req(ucBT_MIC_Volume);	
			DISP_SetTempDisplayMode(DISP_BT_MICVOLUME);
			//
			break;
		#endif
		default:
			break;
	}
#endif
}

void KEY_Short_TuneDown_RMC(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	#ifdef  ST_EV_ADJ
	DISP_SetTempDisplayMode_3Sec(DISP_ST_EV);

	if  (ucST7565_EV_Level == 0)
	{
	}
	else
	{
		--ucST7565_EV_Level;
	}
	#else
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			TUNER_PresetFrequency_Down();
			AUDIO_SetMute(3);
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
	//		DISP_ClearTempDisplayMode();
	//		MENU_Clear();
	//		DISP_SetCurrentDisplay();
			USB_FileChange(0);
			AUDIO_SetMute(0);
			break;
		#ifdef  CD
		case FUNC_CD:
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
	//		DISP_ClearTempDisplayMode();
	//		MENU_Clear();
	//		DISP_SetCurrentDisplay();
			CD_FileChange(0);
			AUDIO_SetMute(0);
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			BT_Key_Main(KEY_TUNE_DOWN, 0);			
			DISP_SetTempDisplayMode(DISP_BT_RWD);
			break;
		#endif
		default:
			break;
	}
	#endif
}

void KEY_Short_Scan(void)
{
	if  (ucDISP_TempDispMode == DISP_TUNER_SEEK_TEST)
	{
		DISP_ClearTempDisplayMode();
		return;
	}

	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			TUNER_SetScan();
			AUDIO_SetMute(3);
			break;
		case FUNC_USB:
			if  (USB_SoundStatus() == 0)
			{
				return;
			}
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			USB_SetScan();
			AUDIO_SetMute(0);
			break;
		#ifdef  CD
		case FUNC_CD:
		#ifdef CD
			if  (CD_SoundStatus() == 0)
			{
				return;
			}
		#endif	
			DISP_ClearTempDisplayMode();
			MENU_Clear();
			DISP_SetCurrentDisplay();
			CD_SetScan();
			AUDIO_SetMute(0);
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			break;
		#endif
		default:
			break;
	}
}

unsigned char KEY_Short_Tune(void)
{
	unsigned char ucRet = 0;
	
#ifdef  MODEL_AGC505X

	if	(ucFUNC_Power == 1)
	{
		switch  (FUNC_GetCurrentFunction())
		{
			case FUNC_TUNER:
				if  (TUNER_ClearTunerMode() == 1)
				{
					return(1);
				}
				if  (TUNER_SoundStatus() == 0)
				{
					return(0);
				}
				break;
		#ifdef CD
			case FUNC_CD:
				if  ((ucCD_Pause == 1) || (CD_SoundStatus() == 0))
				{
					return(0);
				}
			#ifdef  FILE_SEARCH
				if  (ucDISP_TempDispMode == DISP_FILE_SEARCH)
				{
					CD_FileSearchPlay();
			//		DISP_ClearTempDisplayMode();
			//		MENU_Clear();
					DISP_SetCurrentDisplay();
					return(1);
				}
			#endif
				break;
		#endif	
			case FUNC_USB:
				if  ((ucUSB_Pause == 1) || (USB_SoundStatus() == 0))
				{
					return(0);
				}
			#ifdef  FILE_SEARCH
				if  (ucDISP_TempDispMode == DISP_FILE_SEARCH)
				{
					USB_FileSearchPlay();
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					DISP_SetCurrentDisplay();
					return(1);
				}
			#endif
				break;
	#ifdef	BLUETOOTH
			case FUNC_HF:
				break;
	#endif
		}
		ucRet = MENU_KeyMain(KEY_MENU, 0);
		AUDIO_SetMute(0);
	}
	else 
	{
		if	((ucMenuID == MENU_CLOCK_SET_HOUR_ID) || (ucMenuID == MENU_CLOCK_SET_MIN_ID))
		{
			ucRet = MENU_KeyMain(KEY_MENU, 0);
		}
	}

#else
	KEY_Short_Scan();
#endif
	return(ucRet);
}

void KEY_Short_AST(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	
	switch  (FUNC_GetCurrentFunction())
	{
		case FUNC_TUNER:
			if  (TUNER_SetAutoStore() ==1)
			{
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				AUDIO_SetMute(3);
			}
			break;
		case FUNC_USB:
			break;
		#ifdef  CD
		case FUNC_CD:
			break;
		#endif
		#ifdef  BLUETOOTH
		case FUNC_A2DP:
			break;
		#endif
		default:
			break;
	}
}

void KEY_Long_Tune(void)
{		
	switch	(ucMenuID)
	{
#ifdef  BLUETOOTH
//		case MENU_BT_RECENT_ID:	
//			break;
		case MENU_BT_PAIR_ID:
		case MENU_BT_SEL_ID:
		case MENU_BT_SEL_LIST_ID:
		case MENU_BT_DEL_ID:
		case MENU_BT_DEL_LIST_ID:
		case MENU_BT_VOL_ID:
		case MENU_BT_PB_ID:
		case MENU_BT_PB_ACTIVE_ID:
		case MENU_BT_MODE_ID:
		case MENU_BT_MODE_ACTIVE_ID:
			MENU_KeyMain(KEY_POWER, 0);
			return;
			break;
#endif
	}
	if  (OPT_GetOption(OPT_MASK_CLOCK) == 0)
	{
		return;
	}

	if  (ucFUNC_Power == 1)
	{
		switch	(FUNC_GetCurrentFunction())
		{
			case FUNC_TUNER:
				if  (TUNER_SoundStatus() == 1)
				{
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					DISP_SetCurrentDisplay();
					DISP_ClockDisplayModeCtrl();
					AUDIO_SetMute(0);
					AUDIO_BeepOutStart();
				}
				else
				{
					KEY_Short_Menu();
				}
				break;
			#ifdef	CD
			case FUNC_CD:
				if	(ucCD_Pause == 0)
				{
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					DISP_SetCurrentDisplay();
					DISP_ClockDisplayModeCtrl();
					AUDIO_SetMute(0);
					AUDIO_BeepOutStart();
				}
				break;
			#endif
			case FUNC_USB:
				if	(ucUSB_Pause == 0)
				{
					DISP_ClearTempDisplayMode();
					MENU_Clear();
					DISP_SetCurrentDisplay();
					DISP_ClockDisplayModeCtrl();
					AUDIO_SetMute(0);
					AUDIO_BeepOutStart();
				}
				break;
		#ifdef	BLUETOOTH
			case FUNC_HF:
				break;
		#endif
			default:
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				DISP_SetCurrentDisplay();
				DISP_ClockDisplayModeCtrl();
				AUDIO_SetMute(0);
				AUDIO_BeepOutStart();
				break;
		}
	}
	else
	{
		MENU_KeyMain(KEY_MENU, 1);
	}

}

#if 0 
unsigned char KEY_VolumeInvalid(void)
{
	unsigned char ucRet = 0;
	
	switch  (ucFUNC_Current)
	{
		case FUNC_TUNER:
			if  (ucTuner_Mode == TUNER_SEEK)
			{
				ucRet = 1;
			}
			if  (ucTuner_Mode == TUNER_SCAN)
			{
				if  (ucTuner_ModeSeq != TUNER_SCAN_WAIT_5SEC)
				{
					ucRet = 1;
				}
			}
			if  (ucTuner_Mode == TUNER_AST)
			{
				if  (ucTuner_ModeSeq != TUNER_AST_DEMO_WAIT_5S)
				{
					ucRet = 1;
				}
			}
			break;
	#if 0
		case FUNC_USB:
			if  (LC786XXX_GetMediaStatus(FUNC_USB) != LC786X_MS_PLAYBACK)
			{
				ucRet = 1;
			}
			break;
	#ifdef  CD
		case FUNC_CD:
			if  (LC786XXX_GetMediaStatus(FUNC_CD) != LC786X_MS_PLAYBACK)
			{
				ucRet = 1;
			}
			break;
	#endif
	#endif 
	}
	return(ucRet);
}
#endif

void KEY_Short_VolumeUp(void)
{
#ifdef  MODEL_AGC5030
	if  (MENU_KeyMain(KEY_VOL_UP, 0) == 1)
	{
		return;
	}
#endif
#ifdef  MODEL_ARA5040
	if  (MENU_KeyMain(KEY_VOL_UP, 0) == 1)
	{
		return;
	}
#endif

	if  ((TUNER_SoundStatus() == 0) || (ucFUNC_Power == 0))
	{
		return;
	}
	
	if  (USB_SoundStatus() == 0)
	{
		return;
	}
#ifdef CD
	if  (CD_SoundStatus() == 0)
	{
		return;
	}
#endif
	
#ifdef	AUTO_GUIDE
	if	(AG_GetAnnounceStatus() == AG_ANNOUNCE_ON)
	{
		AG_VolumeChange(1);
		return;
	}
#endif

	switch  (FUNC_GetCurrentFunction())
	{
		default:
			AUDIO_VolumeChange(1);
			break;
	#ifdef  BLUETOOTH
		case FUNC_HF:
		case FUNC_A2DP:
			BT_BluetoothVolume(1, 1);
			DISP_SetTempDisplayMode(DISP_BT_VOLUME);
			break;
	#endif
	}

	AUDIO_SetMute(0);
#ifdef CD
	if  (FUNC_GetCurrentFunction() == FUNC_CD)
	{
		CD_PauseOff(1);
	}
#endif
	if  (FUNC_GetCurrentFunction() == FUNC_USB)
	{
		USB_PauseOff(1);
	}
}

void KEY_Short_VolumeDown(void)
{
#ifdef  MODEL_ARA5040
	if  (MENU_KeyMain(KEY_VOL_DOWN, 0) == 1)
	{
		return;
	}
#endif
#ifdef  MODEL_AGC5030
	if  (MENU_KeyMain(KEY_VOL_DOWN, 0) == 1)
	{
		return;
	}
#endif

	if  ((TUNER_SoundStatus() == 0) || (ucFUNC_Power == 0))
	{
		return;
	}
	if  (USB_SoundStatus() == 0)
	{
		return;
	}
#ifdef CD
	if  (CD_SoundStatus() == 0)
	{
		return;
	}
#endif	
	
#ifdef	AUTO_GUIDE
	if  (AG_GetAnnounceStatus() == AG_ANNOUNCE_ON)
	{
		AG_VolumeChange(0);
		return;
	}
#endif

	switch  (FUNC_GetCurrentFunction())
	{
		default:
			AUDIO_VolumeChange(0);
			break;
#ifdef	BLUETOOTH
		case FUNC_HF:
		case FUNC_A2DP:
			BT_BluetoothVolume(0, 1);
			DISP_SetTempDisplayMode(DISP_BT_VOLUME);
			break;
#endif
	}

	AUDIO_SetMute(0);
#ifdef CD
	if  (FUNC_GetCurrentFunction() == FUNC_CD)
	{
		CD_PauseOff(1);
	}
#endif
	if  (FUNC_GetCurrentFunction() == FUNC_USB)
	{
		USB_PauseOff(1);
	}
}

#ifdef	DRV_SPK

void KEY_Short_DSPK(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	AUDIO_ChangeSpeaker();
	DISP_SetTempDisplayMode_3Sec(DISP_DRIVER_SPEAKER);
}
#endif


void KEY_MultiKey_Local(unsigned char ucMode)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	if  (FUNC_GetCurrentFunction() != FUNC_TUNER)
	{
		return;
	}

	DISP_ClearTempDisplayMode();
	MENU_Clear();
	DISP_SetCurrentDisplay();
	AUDIO_BeepOutStart();
	switch  (ucMode)
	{
		case 0:
			ucUI_OPT_Local = LOCAL_ASIA;
			DISP_SetTempDisplayMode_6Sec(DISP_LOCAL_ASIA);
		#ifdef  USER_WATCHDOG
			CPU_WatchDogEnable();
		#endif
			break;
		case 1:
			ucUI_OPT_Local = LOCAL_NORTH_AMERICA;
			DISP_SetTempDisplayMode_6Sec(DISP_LOCAL_NORTH_AMERICA);
		#ifdef  USER_WATCHDOG
			CPU_WatchDogEnable();
		#endif
			break;
		case 2:
			ucUI_OPT_Local = LOCAL_SOUTH_AMERICA;
			DISP_SetTempDisplayMode_6Sec(DISP_LOCAL_SOUTH_AMERICA);
		#ifdef  USER_WATCHDOG
			CPU_WatchDogEnable();
		#endif
			break;
		case 3:
			ucUI_OPT_Local = LOCAL_EUROPE;
			DISP_SetTempDisplayMode_6Sec(DISP_LOCAL_EUROPE);
		#ifdef  USER_WATCHDOG
			CPU_WatchDogEnable();
		#endif
			break;
	}
	OPT_WriteOptionMemory();
}

unsigned char KEY_FirmwareUpdate(unsigned char ucLong, KEY_ID ucKeyID)
{
	unsigned char ucDes = 0;
	if  (ucLong == 1)
	{
		switch  (ucKeyID)
		{
			case KEY_FIRMWARE_UPDATE:
				DISP_SetTempDisplayMode_10Sec(DISP_FIRMWARE_HOST);
				ucDes = 1;
				break;
		}
	}
	else
	{
		switch  (ucKeyID)
		{
			case KEY_TUNE:
				if  (ucDISP_TempDispMode == DISP_FIRMWARE_HOST)
				{
				#ifdef  M16C_64G
					s2tic = 0;		// Interrupt Disable : Level 6
				#endif
					BOOT_Update_Start(BOOT_HOST_UPDATE);
					ucDes = 1;
				}
				#ifdef  BLUETOOTH
				else  if  (ucDISP_TempDispMode == DISP_FIRMWARE_BLUETOOTH)
				{
				#ifdef  M16C_64G
					s2tic = 0;		// Interrupt Disable : Level 6
				#endif
					BT_DFU_Main();//BOOT_Update_Start(BOOT_BLUETOOTH_UPDATE);
					ucDes = 1;
				}
				#endif
				else  if  (ucDISP_TempDispMode == DISP_FIRMWARE_USB)
				{
					DRV_LC786XXX_FirmwareUpdate_ON = 1;
					ucDes = 1;				
				}
				break;
			case KEY_TUNE_DOWN:
			case KEY_TUNE_UP:
				if  (ucDISP_TempDispMode == DISP_FIRMWARE_HOST)
				{
				#ifdef  BLUETOOTH
					if  (OPT_GetOption(OPT_MASK_BT) == 1)
					{
						DISP_SetTempDisplayMode_10Sec(DISP_FIRMWARE_BLUETOOTH);
					}
					else
					{
						DISP_SetTempDisplayMode_10Sec(DISP_FIRMWARE_USB);
					}
				#else					
					DISP_SetTempDisplayMode_10Sec(DISP_FIRMWARE_USB);
				#endif
					ucDes = 1;
				}
				#ifdef  BLUETOOTH
				else  if  (ucDISP_TempDispMode == DISP_FIRMWARE_BLUETOOTH)
				{
					DISP_SetTempDisplayMode_10Sec(DISP_FIRMWARE_USB);
					ucDes = 1;
				}
				#endif
				else  if  (ucDISP_TempDispMode == DISP_FIRMWARE_USB)
				{
					DISP_SetTempDisplayMode_10Sec(DISP_FIRMWARE_HOST);
					ucDes = 1;
				}
				break;
		}
	}

	return(ucDes);
}

 
void KEY_Short_EQFlat(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	AUDIO_EQ_Flat();
	AUDIO_SetAudio();
	DISP_SetTempDisplayMode_3Sec(DISP_EQ_FLAT);
}

void KEY_Short_TunerPresetClear(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	if  (FUNC_GetCurrentFunction() != FUNC_TUNER)
	{
		return;
	}
	TUNER_PresetInitialize();								
	DISP_SetTempDisplayMode_3Sec(DISP_TUNER_PRESET_CLEAR);
}

void KEY_Long_SeekDisplay(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	if  (FUNC_GetCurrentFunction() != FUNC_TUNER)
	{
		return;
	}
	DISP_SetTempDisplayMode_6Sec(DISP_TUNER_SEEK_TEST);
}

void KEY_Long_RadioDisplay(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	if  (FUNC_GetCurrentFunction() != FUNC_TUNER)
	{
		return;
	}

	ucDISP_RadioInfo_Active = 0x01;
//	DISP_SetTempDisplayMode_6Sec(DISP_TUNER_INFO);
}

void KEY_Long_BluetoothTest(void)
{
	if  (ucFUNC_Power == 0)
	{
		return;
	}
	DISP_SetTempDisplayMode_6Sec(DISP_BT_TEST);
}

void KEY_ShortPushMain(KEY_ID ucKeyID)
{
	if  (KEY_TelMute_Valid(ucKeyID) == 0)
	{
		return;
	}
	switch	(ucKeyID)
	{
		case KEY_RMC_VOL_DOWN:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
			}
			else
			{
				KEY_Short_VolumeDown();
				ucKEY_Action = 1;
			}
			break;
		case KEY_RMC_VOL_UP:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
			}
			else
			{
				KEY_Short_VolumeUp();
				ucKEY_Action = 1;
			}			break;
	#ifdef  MODEL_ARA5040
		case KEY_LOUD:
			KEY_Short_Loud();
			ucKEY_Action = 1;
			break;
		case KEY_FM:
			KEY_Short_Band(FM);
			ucKEY_Action = 1;
			break;
		case KEY_AM:
			KEY_Short_Band(AM);
			ucKEY_Action = 1;
			break;
	#endif
	#ifdef  MODEL_AGC5030
		case KEY_MODE:
			KEY_Short_Mode();
			ucKEY_Action = 1;
			break;
		case KEY_BAND:
			KEY_Short_Band();
			ucKEY_Action = 1;
			break;
	#endif
	#ifdef  MODEL_AGC505X
		case KEY_MODE:
			KEY_Short_Mode();
			ucKEY_Action = 1;
			break;
		case KEY_BAND:
			KEY_Short_Band();
			ucKEY_Action = 1;
			break;
		case KEY_SCAN:
		#ifdef  BLUETOOTH
			if  (BT_HF_CallStatus()== 0)
			{
				KEY_Short_Scan();
				ucKEY_Action = 1;
			}
		#else
			KEY_Short_Scan();
			ucKEY_Action = 1;
		#endif
			break;
		case KEY_AST:
		#ifdef  BLUETOOTH
			if  (BT_HF_ConnectStatus()== 0)
			{
				KEY_Short_AST();
				ucKEY_Action = 1;
			}
		#else
			KEY_Short_AST();
			ucKEY_Action = 1;
		#endif
			break;
	#ifdef  DRV_SPK
//		case KEY_DSPK:
//		#ifdef  BLUETOOTH
//			if  (BT_HF_CallStatus()== 0)
//			{
//				KEY_Short_DSPK();
//				ucKEY_Action = 1;
//			}
//		#else
//			KEY_Short_DSPK();
//			ucKEY_Action = 1;
//		#endif
//			break;
	#endif
		case KEY_SEEK_UP:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				KEY_Short_SeekUP();
				ucKEY_Action = 1;
			}
			break;
		case KEY_TRACK_DOWN:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				KEY_Short_TuneDown();
				ucKEY_Action = 1;
			}
			break;
	#endif
	#ifdef  MIC
		case KEY_MIC:
			KEY_Short_MIC();
			ucKEY_Action = 1;
			break;
	#endif
		case KEY_RMC_MODE:
			KEY_Short_Mode_TotalFunction();
			ucKEY_Action = 1;
			break;
		case KEY_AUX:
			KEY_Short_AUX();
			ucKEY_Action = 1;
			break;
		case KEY_USB:
			KEY_Short_USB();
			ucKEY_Action = 1;
			break;
	#ifdef  CD
		case KEY_CD:
			KEY_Short_CD();
			ucKEY_Action = 1;
			break;
	#endif
		case KEY_TUNE:
	#if  0
		#ifdef  CD
			if  ((FUNC_GetCurrentFunction() == FUNC_USB) || (FUNC_GetCurrentFunction() == FUNC_CD))
		#else
			if  (FUNC_GetCurrentFunction() == FUNC_USB)
		#endif
			{
				if  (KEY_FirmwareUpdate(0,KEY_TUNE) == 0)
				{
					KEY_Short_Tune();
				}
				ucKEY_Action = 1;
			}
	#endif
			break;
		case KEY_MENU:
		#ifdef  OPTIONAL_CLOCK
			if  (OPT_GetOption(OPT_MASK_CLOCK) == 0)
			{
				KEY_Short_Menu();
				ucKEY_Action = 1;
			}
		#endif
			break;
		case KEY_NUM1:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				if  ((TUNER_SoundStatus() == 1) && (ucAUDIO_Mute == 0))
				{
				}
				else
				{
					KEY_Short_Num1_Pause();
					ucKEY_Action = 1;
				}
			}
			else
			{
				KEY_Short_Num1_Pause();
				ucKEY_Action = 1;
			}
			break;
		case KEY_NUM2:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				if  ((TUNER_SoundStatus() == 1) && (ucAUDIO_Mute == 0))
				{
				}
				else
				{
					KEY_Short_Num2_Repeat();
					ucKEY_Action = 1;
				}
			}
			else
			{
				KEY_Short_Num2_Repeat();
				ucKEY_Action = 1;
			}
			break;
		case KEY_NUM3:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				if  ((TUNER_SoundStatus() == 1) && (ucAUDIO_Mute == 0))
				{
				}
				else
				{
					KEY_Short_Num3_Random();
					ucKEY_Action = 1;
				}
			}
			else
			{
				KEY_Short_Num3_Random();
				ucKEY_Action = 1;
			}
			break;
		case KEY_NUM4:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				if  ((TUNER_SoundStatus() == 1) && (ucAUDIO_Mute == 0))
				{
				}
				else
				{
					KEY_Short_Num4_Info();
					ucKEY_Action = 1;
				}
			}
			break;
		case KEY_NUM5:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				if  ((TUNER_SoundStatus() == 1) && (ucAUDIO_Mute == 0))
				{
				}
				else
				{
					KEY_Short_Num5_DirDown();
					ucKEY_Action = 1;
				}
			}
			else
			{
				KEY_Short_Num5_DirDown();
				ucKEY_Action = 1;
			}
			break;
		case KEY_NUM6:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				if  ((TUNER_SoundStatus() == 1) && (ucAUDIO_Mute == 0))
				{
				}
				else
				{
					KEY_Short_Num6_DirUp();
					ucKEY_Action = 1;
				}
			}
			else
			{
				KEY_Short_Num6_DirUp();
				ucKEY_Action = 1;
			}
			break;
	}
}

void KEY_ShortKeyMain(KEY_ID ucKeyID)
{
#if	0//def BLUETOOTH
	if	(KEY_GetBTPairingInvalid(ucKeyID, 0) == 0)
	{
		return;
	}
#endif
	if  (KEY_TelMute_Valid(ucKeyID) == 0)
	{
		return;
	}

	switch  (ucKeyID)
	{
		case KEY_RMC_VOL_DOWN:
			KEY_Short_VolumeDown();
			usKEY_LongKey_Timer10msec = 50/10;
			break;
		case KEY_RMC_VOL_UP:
			KEY_Short_VolumeUp();
			usKEY_LongKey_Timer10msec = 50/10;
			break;
		case KEY_POWER:
			KEY_Short_Power();
			break;
	#ifdef  MODEL_ARA5040
		case KEY_LOUD:
			KEY_Short_Loud();
			break;
		case KEY_FM:
			KEY_Short_Band(FM);
			break;
		case KEY_AM:
			KEY_Short_Band(AM);
			break;
	#endif
	#ifdef  MODEL_AGC5030
		case KEY_MODE:
			KEY_Short_Mode();
			break;
		case KEY_BAND:
			KEY_Short_Band();
			break;
	#endif
	#ifdef  MODEL_AGC505X
		case KEY_SEEK_UP:
			KEY_Short_SeekUP();
			break;
		case KEY_TRACK_DOWN:
			KEY_Short_TuneDown();
			break;
		case KEY_SCAN:
			KEY_Short_Scan();
			break;
		case KEY_AST:
			KEY_Short_AST();
			break;
	#ifdef  DRV_SPK
		case KEY_DSPK:
			KEY_Short_DSPK();
			break;
	#endif
	#endif
		case KEY_RMC_MODE:
			KEY_Short_Mode_TotalFunction();
			break;
		case KEY_AUX:
			KEY_Short_AUX();
			break;
		case KEY_USB:
			KEY_Short_USB();
			break;
		#ifdef  CD
		case KEY_CD:
			KEY_Short_CD();
			break;
		#endif
		case KEY_MENU:
		#ifdef  OPTIONAL_CLOCK
			if  (OPT_GetOption(OPT_MASK_CLOCK) == 1)
		#endif
			{
				KEY_Short_Menu();
			}
			break;
		case KEY_NUM1:
			KEY_Short_Num1_Pause();
			break;
		case KEY_NUM2:
			KEY_Short_Num2_Repeat();
			break;
		case KEY_NUM3:
			KEY_Short_Num3_Random();
			break;
		case KEY_NUM4:
			KEY_Short_Num4_Info();
			break;
		case KEY_NUM5:
			KEY_Short_Num5_DirDown();
			break;
		case KEY_NUM6:
			KEY_Short_Num6_DirUp();
			break;
		case KEY_TUNE_UP:
			if  (KEY_FirmwareUpdate(0,KEY_TUNE_UP) == 0)
			{
				KEY_Short_SearchUp();
			}
			break;
		case KEY_RMC_TUNE_UP:
			KEY_Short_TuneUp_RMC();
			break;
		case KEY_TUNE_DOWN:
			if  (KEY_FirmwareUpdate(0,KEY_TUNE_DOWN) == 0)
			{
				KEY_Short_SearchDown();
			}
			break;
		case KEY_RMC_TUNE_DOWN:
			KEY_Short_TuneDown_RMC();
			break;
		case KEY_TUNE:
			if  (KEY_FirmwareUpdate(0,KEY_TUNE) == 0)
			{
				KEY_Short_Tune();
			}
			break;
		case KEY_VOL_UP:
			KEY_Short_VolumeUp();
			break;
		case KEY_VOL_DOWN:
			KEY_Short_VolumeDown();
			break;
		#ifdef  CD
		case KEY_EJECT:
			CD_SetEject(0);
			break;
		#endif
		#ifdef  BLUETOOTH
		case KEY_CALL:			
			if  (DISP_BluetoothTestMode() == 1)
			{		
				MENU_Clear();
				DISP_SetTempDisplayMode_6Sec(DISP_BT_MIC);
				MV_TX_SYS_StartSpkMicLoopBack();
				FUNC_FunctionChangeStart(FUNC_LPB, FUNC_CHANGE_SEQ0);
				MV_TX_HF_ReadMICVolume_Req();
			}
			else
			{
				BT_Key_Main(KEY_CALL, 0);
			}
			break;
		case KEY_HANG_UP:
			if  (FUNC_GetCurrentFunction() == FUNC_LPB)
			{
				MV_TX_SYS_StopSpkMicLoopBack();
				DISP_ClearTempDisplayMode();
				MENU_Clear();
				FUNC_FunctionChangeStart(FUNC_GetPreviousFunction(), FUNC_CHANGE_SEQ0);
				
			}
			BT_Key_Main(KEY_HANG_UP, 0);
			break;
		#endif
	}
}

void KEY_LongKeyMain(KEY_ID ucKeyID)
{
#ifdef BLUETOOTH
	if  (KEY_GetBTPairingInvalid(ucKeyID, 1) == 0)
	{
		return;
	}
#endif
	if  (KEY_TelMute_Valid(ucKeyID) == 0)
	{
		return;
	}
	switch  (ucKeyID)
	{
		case KEY_RMC_VOL_DOWN:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				KEY_Long_SearchDown();
			}
			break;
		case KEY_RMC_VOL_UP:
			if  (FUNC_GetCurrentFunction() == FUNC_TUNER)
			{
				KEY_Long_SearchUp();
			}
			break;
		case KEY_POWER:
			KEY_Long_Power();
			break;
	#ifdef  MODEL_ARA5040
		case KEY_LOUD:
			break;
		case KEY_FM:
	//		KEY_Short_Band(FM);
			break;
		case KEY_AM:
	//		KEY_Short_Band(AM);
			break;
	#endif
	#ifdef  MODEL_AGC5030
		case KEY_MODE:
			KEY_Short_Mode();
			break;
		case KEY_BAND:
			KEY_Short_Band();
			break;
	#endif
	#ifdef  MODEL_AGC505X
		case KEY_AST:
		#ifdef  BLUETOOTH
			BT_Key_Main(KEY_CALL, 1);
		#endif
			break;
		case KEY_SCAN:
		#ifdef  BLUETOOTH
			BT_Key_Main(KEY_HANG_UP, 1);
		#endif
			break;
	#ifdef  DRV_SPK
		case KEY_DSPK:
		#ifdef  BLUETOOTH
			BT_Key_Main(KEY_HANG_UP, 1);
		#endif
			break;
	#endif
		case KEY_SEEK_UP:
		case KEY_RMC_TUNE_UP:
			KEY_Long_SearchUp();
			break;
		case KEY_TRACK_DOWN:
		case KEY_RMC_TUNE_DOWN:
			KEY_Long_SearchDown();
			break;
	#endif
		case KEY_RMC_MODE:
			KEY_Short_Mode_TotalFunction();
			break;
		case KEY_AUX:
			break;
		case KEY_USB:
			break;
		case KEY_MENU:
			KEY_Long_Menu();
			break;
		case KEY_NUM1:
			KEY_Long_Num1_Pause();
			break;
		case KEY_NUM2:
			KEY_Long_Num2_Repeat();
			break;
		case KEY_NUM3:
			KEY_Long_Num3_Random();
			break;
		case KEY_NUM4:
			KEY_Long_Num4_Info();
			break;
		case KEY_NUM5:
			KEY_Long_Num5_DirDown();
			break;
		case KEY_NUM6:
			KEY_Long_Num6_DirUp();
			break;
		case KEY_TUNE_UP:
	#ifdef  MODEL_AGC5030
		case KEY_RMC_TUNE_UP:
	#endif
	#ifdef  MODEL_ARA5040
		case KEY_RMC_TUNE_UP:
	#endif
			KEY_Long_SearchUp();
			break;
		case KEY_TUNE_DOWN:
	#ifdef  MODEL_AGC5030
		case KEY_RMC_TUNE_DOWN:
	#endif
	#ifdef  MODEL_ARA5040
		case KEY_RMC_TUNE_DOWN:
	#endif
			KEY_Long_SearchDown();
			break;
		case KEY_TUNE:
			KEY_Long_Tune();
		case KEY_VOL_UP:
			break;
		case KEY_VOL_DOWN:
			break;
	#ifdef  CD
		case KEY_CD:
	//		KEY_Short_CD();
			break;
		case KEY_EJECT:
			CD_SetEject(1);
			break;
	#endif
	#ifdef  BLUETOOTH
		case KEY_CALL:
			BT_Key_Main(KEY_CALL, 1);
			break;
		case KEY_HANG_UP:
			BT_Key_Main(KEY_HANG_UP, 1);
			break;
	#endif
		case KEY_LOCAL_ASIA:
			KEY_MultiKey_Local(0);
			break;
		case KEY_LOCAL_NAMERICA:
			KEY_MultiKey_Local(1);
			break;
		case KEY_LOCAL_SAMERICA:
			KEY_MultiKey_Local(2);
			break;
		case KEY_LOCAL_EURO:
			KEY_MultiKey_Local(3);
			break; 
		case KEY_SEEK_TEST:
			KEY_Long_SeekDisplay();												
			break;
		case KEY_RADIO_INFO:
			KEY_Long_RadioDisplay();
			break;	
		case KEY_FIRMWARE_UPDATE:
			KEY_FirmwareUpdate(1, KEY_FIRMWARE_UPDATE);
			break;
		case KEY_EQ_FLAT:
			KEY_Short_EQFlat();
			break;	
		case KEY_PRESET_CLEAR:
			KEY_Short_TunerPresetClear();
			break;	
		#ifdef BLUETOOTH
		case KEY_BT_TEST:
			KEY_Long_BluetoothTest();
			break;	
		#endif
	}
}

void KEY_SetLongKeyTimer(KEY_ID ucKey)
{
	usKEY_LongKey_Timer10msec = 800/10;
	switch  (ucKey)
	{
		case KEY_RADIO_INFO:
		case KEY_LOCAL_ASIA:
		case KEY_LOCAL_NAMERICA:
		case KEY_LOCAL_SAMERICA:
		case KEY_LOCAL_EURO:
		case KEY_FIRMWARE_UPDATE:
			usKEY_LongKey_Timer10msec = 3000/10;
			break;
//		case KEY_TUNE_UP:
//		case KEY_TUNE_DOWN:
//			usKEY_LongKey_Timer10msec = 1000/10;
//			break;
		case KEY_EQ_FLAT:
		case KEY_PRESET_CLEAR:
		case KEY_BT_TEST:
			usKEY_LongKey_Timer10msec = 1500/10;
			break;
		case KEY_NONE:
			LOG_MATRIX("NNNNNNNNNNNNNNN");
			break;
		default:
			LOG_MATRIX("XXXXXXXXXXXXXXX");
			break;
	}
	LOG_KEY("KEY_SetLongKeyTimer:%d",usKEY_LongKey_Timer10msec);
}

//unsigned char ucKEY_TuneUpDownKey_Timer50msec;
//unsigned char ucKEY_TuneUpDownKey_Count;

void KEY_ProcessMain(void)
{	
	if  (ucKEY_New == ucKEY_Last)	// Long Key
	{
		if  ((ucKEY_Last != KEY_NONE) && (ucKEY_Action == 0) && (usKEY_LongKey_Timer10msec == 0))
		{
			ucKEY_Action = 1;
			KEY_LongKeyMain(ucKEY_Last);
			LOG_KEY("KEY_Long:%d", ucKEY_Last);
		}
		if  ((ucKEY_Last != KEY_NONE) && (ucKEY_Action == 0))
		{
			KEY_ShortPushMain(ucKEY_Last);
		}
	//	ucKEY_Change_Timer5msec = 20/5;
	}
	else
	{
	//	if  ((ucKEY_New != KEY_NONE) && (ucKEY_Change_Timer5msec != 0))
	//	{
	//		return;
	//	}
	#if  1
		if  (ucDISP_RadioInfo_Active != 0)
		{
			if  ((ucKEY_New != KEY_NONE) && (ucKEY_New != KEY_TUNE_UP) && (ucKEY_New != KEY_TUNE_DOWN))
			{
				ucDISP_RadioInfo_Active = 0;
			}
		}
		if  ((ucKEY_Action == 0) && (ucKEY_Last != KEY_NONE) && (ucKEY_New == KEY_NONE) && (ucKEY_ShortKey_Timer5msec == 0))
		{
			LOG_KEY("KEY_Short:%d", ucKEY_Last);
			KEY_ShortKeyMain(ucKEY_Last);
		}

		if  ((ucKEY_Action == 1) && ((ucKEY_New != KEY_TUNE_UP) && (ucKEY_New != KEY_TUNE_DOWN)))
		{
			if  ((ucKEY_Last == KEY_TUNE_UP) || (ucKEY_Last == KEY_TUNE_DOWN))
			{
				KEY_Long_SearchRelease();
			}
		}
		if  ((ucKEY_Action == 1) && ((ucKEY_New != KEY_RMC_TUNE_UP) && (ucKEY_New != KEY_RMC_TUNE_DOWN)))
		{
			if  ((ucKEY_Last == KEY_RMC_TUNE_UP) || (ucKEY_Last == KEY_RMC_TUNE_DOWN))
			{
				KEY_Long_SearchRelease();
			}
		}
	#ifdef  MODEL_AGC505X
		if  ((ucKEY_Action == 1) && ((ucKEY_New != KEY_TRACK_DOWN) && (ucKEY_New != KEY_SEEK_UP)))
		{
			if  ((ucKEY_Last == KEY_TRACK_DOWN) || (ucKEY_Last == KEY_SEEK_UP))
			{
				KEY_Long_SearchRelease();
			}
		}
	#endif
		if  (ucKEY_New == KEY_NONE)
		{
			ucKEY_Action = 0;
		}
		ucKEY_Last = ucKEY_New;
		KEY_SetLongKeyTimer(ucKEY_Last);
		ucKEY_ShortKey_Timer5msec = 50/5;
	#endif
	}
}

#define	KEY_OUT(X)	{ \
						p9 = p9 & 0xF0;	\
						p9 = p9 | (X & 0x0F);	\
					}
#define	KEY_OUT_DIR(X)	{	\
							unsigned char ucTemp;	\
							p9 = p9 & 0xF0;			\
							ucTemp = (pd9 & 0xF0);	\
							prcr = 0x04;			\
							pd9 = ucTemp;			\
							ucTemp = pd9 | X;		\
							prcr = 0x04;			\
							pd9 = ucTemp;			\
						}
#define	KEY_IN		(p5 >> 3) & 0x1B//(p5 & 0xD8) >> 3

void KEY_Delay(unsigned char ucCnt)
{
	unsigned char i;

	for(i = 0; i < ucCnt; ++i)
	{
	
	}
}

unsigned char KEY_ReadKeyCnt(unsigned char ucKeyIn)
{
	unsigned char ucCnt = 0;

	if  (ucKeyIn & KEY_MATRIX_INPUT1)
	{
		++ucCnt;
	}
	if  (ucKeyIn & KEY_MATRIX_INPUT2)
	{
		++ucCnt;
	}
	if  (ucKeyIn & KEY_MATRIX_INPUT3)
	{
		++ucCnt;
	}
	if  (ucKeyIn & KEY_MATRIX_INPUT4)
	{
		++ucCnt;
	}
	return(ucCnt);
}

#ifdef  MODEL_AGC505X

#define	MATRIX_NUM1	KEY_MATRIX_O2I2
#define	MATRIX_NUM2	KEY_MATRIX_O3I2
#define	MATRIX_NUM3	KEY_MATRIX_O4I2
#define	MATRIX_NUM4	KEY_MATRIX_O1I3
#define	MATRIX_NUM5	KEY_MATRIX_O2I3
#define	MATRIX_NUM6	KEY_MATRIX_O3I3
#define	MATRIX_BAND		KEY_MATRIX_O1I1
#define	MATRIX_POWER	KEY_MATRIX_O2I1
#define	MATRIX_MODE		KEY_MATRIX_O3I1
#define	MATRIX_AST		KEY_MATRIX_O4I1
#define	MATRIX_DSPK		KEY_MATRIX_O1I2
#define	MATRIX_TUNE		KEY_MATRIX_O1I4
#define	MATRIX_TRACK_DN		KEY_MATRIX_O4I3
#define	MATRIX_SEEK_UP		KEY_MATRIX_O2I4
#define	MATRIX_MIC		KEY_MATRIX_O3I4


void KEY_MakeMatrixKey(void)		// AGC505X
{
	KEY_ID ucKey = KEY_NONE;

#if  0
	LOG_MATRIX("<<NUMBER:%d>>", ucKEY_MatrixCnt);
	if  (MATRIX_MIC)
	{
		LOG_MATRIX("MIC");
		ucKey = KEY_NONE;
	}
	if  (MATRIX_SEEK_UP)
	{
		LOG_MATRIX("SEEK UP");
	}
	if  (MATRIX_TRACK_DN)
	{
		LOG_MATRIX("TRACK DN");
	}
	if  (MATRIX_TUNE)
	{
		LOG_MATRIX("TUNE");
	}
	if  (MATRIX_DSPK)
	{
		LOG_MATRIX("DSPK");
	}
	if  (MATRIX_AST)
	{
		LOG_MATRIX("AST");
	}
	if  (MATRIX_MODE)
	{
		LOG_MATRIX("MODE");
	}
	if  (MATRIX_POWER)
	{
		LOG_MATRIX("POWER");
	}
	if  (MATRIX_BAND)
	{
		LOG_MATRIX("BAND");
	}
	if  (MATRIX_NUM1)
	{
		LOG_MATRIX("NUM1");
	}
	if  (MATRIX_NUM2)
	{
		LOG_MATRIX("NUM2");
	}
	if  (MATRIX_NUM3)
	{
		LOG_MATRIX("NUM3");
	}
	if  (MATRIX_NUM4)
	{
		LOG_MATRIX("NUM4");
	}
	if  (MATRIX_NUM5)
	{
		LOG_MATRIX("NUM5");
	}
	if  (MATRIX_NUM6)
	{
		LOG_MATRIX("NUM6");
	}
#endif

	switch  (ucKEY_MatrixCnt)
	{
		case 0:	// None Key
			break;
		case 1:	// 1 Key
			if  (KEY_MATRIX_O1I1)
			{
				ucKey = KEY_BAND;
			}
			if  (KEY_MATRIX_O2I1)
			{
				ucKey = KEY_POWER;
			}
			if  (KEY_MATRIX_O3I1)
			{
				if  ((OPT_GetOption(OPT_MASK_AVC)) && (OPT_GetOption(OPT_MASK_CD)))
				{
					ucKey = KEY_USB;
				}
				else
				{
					ucKey = KEY_MODE;
				}
			}
			if  (KEY_MATRIX_O4I1)
			{
				ucKey = KEY_AST;
			}
			if  (KEY_MATRIX_O1I2)
			{
				if  (OPT_GetOption(OPT_MASK_AVC) == 1)
				{
					ucKey = KEY_SCAN;
				}
				else
				{
					ucKey = KEY_DSPK;
				}
			}
			if  (KEY_MATRIX_O2I2)
			{
				ucKey = KEY_NUM1;
			}
			if  (KEY_MATRIX_O3I2)
			{
				ucKey = KEY_NUM2;
			}
			if  (KEY_MATRIX_O4I2)
			{
				ucKey = KEY_NUM3;
			}
			if  (KEY_MATRIX_O1I3)
			{
				ucKey = KEY_NUM4;
			}
			if  (KEY_MATRIX_O2I3)
			{
				ucKey = KEY_NUM5;
			}
			if  (KEY_MATRIX_O3I3)
			{
				ucKey = KEY_NUM6;
			}
			if  (KEY_MATRIX_O4I3)
			{
				ucKey = KEY_TRACK_DOWN;
			}
			if  (KEY_MATRIX_O1I4)
			{
				ucKey = KEY_TUNE;
			}
			if  (KEY_MATRIX_O2I4)
			{
				ucKey = KEY_SEEK_UP;
			}
			if  (KEY_MATRIX_O3I4)
			{
				if  (OPT_GetOption(OPT_MASK_AVC))
				{
					if  (OPT_GetOption(OPT_MASK_CD))
					{
						ucKey = KEY_CD;
					}
				}
				else
				{
					ucKey = KEY_MIC;
				}
			}
			break;
		case 3:	// 3Key
		case 4:
			if  (MATRIX_NUM1 && MATRIX_NUM4 && MATRIX_NUM6)
			{
				ucKey = KEY_FIRMWARE_UPDATE;
			}
			
			if  (MATRIX_NUM1 && MATRIX_NUM6 && MATRIX_TRACK_DN)
			{
				ucKey = KEY_LOCAL_ASIA;
			}
			
			if  (MATRIX_NUM1 && MATRIX_NUM4 && MATRIX_TRACK_DN)
			{
				ucKey = KEY_LOCAL_NAMERICA;
			}
			
			if  (MATRIX_NUM2 && MATRIX_NUM5 && MATRIX_TRACK_DN)
			{
				ucKey = KEY_LOCAL_SAMERICA;
			}
			
			if  (MATRIX_NUM2 && MATRIX_NUM4 && MATRIX_TRACK_DN)		// NG
			{
				ucKey = KEY_LOCAL_EURO;
			}
						
			if  (MATRIX_NUM1 && MATRIX_NUM2 && MATRIX_TUNE)
			{
				ucKey = KEY_EQ_FLAT;
			}
			
			if  (MATRIX_NUM1 && MATRIX_NUM2 && MATRIX_BAND)
			{
				ucKey = KEY_SEEK_TEST;
			}
			
			if  (MATRIX_NUM1 && MATRIX_NUM2 && MATRIX_TRACK_DN)		// NG
			{
				ucKey = KEY_PRESET_CLEAR;
			}
			
			if  (MATRIX_NUM1 && MATRIX_NUM4 && MATRIX_SEEK_UP)
			{
				ucKey = KEY_RADIO_INFO;
			}
			
			if  (MATRIX_NUM1 && MATRIX_NUM2 && MATRIX_DSPK)
			{
				if  (OPT_GetOption(OPT_MASK_BT))
				{
					ucKey = KEY_BT_TEST;
				}
			}
			break;
	}

	ucKEY_MatrixKey = ucKey;
}
#endif

#define	MKEY_SEQ_INIT			0
#define	MKEY_SEQ_PRESCAN		1
#define	MKEY_SEQ_SCAN_READ_OUT1	2
#define	MKEY_SEQ_SCAN_READ_OUT2	3
#define	MKEY_SEQ_SCAN_READ_OUT3	4
#define	MKEY_SEQ_SCAN_READ_OUT4	5

void KEY_MatrixInput(void)
{
	unsigned char ucTemp;

	switch  (ucKEY_MatrixSeq)
	{
		case MKEY_SEQ_INIT:
			KEY_OUT_DIR(0x0F);
			KEY_OUT(0x0F);		
			ucKEY_MatrixSeq = MKEY_SEQ_PRESCAN;
			break;
		case MKEY_SEQ_PRESCAN:		// Pre-Scan
			KEY_OUT_DIR(0x0F);
			KEY_OUT(0x0F);
			ucKEY_MatrixCnt = 0;
			if  (KEY_IN)
			{				
				ucKEY_MatrixSeq = MKEY_SEQ_SCAN_READ_OUT1;
				KEY_OUT_DIR(0x01);
				KEY_OUT(0x01);
			}
			break;
		case MKEY_SEQ_SCAN_READ_OUT1:
			ucKEY_Matrix[0] = KEY_IN;
			ucKEY_MatrixCnt = ucKEY_MatrixCnt + KEY_ReadKeyCnt(ucKEY_Matrix[0]);
			KEY_OUT_DIR(0x02);
			KEY_OUT(0x02);
			ucKEY_MatrixSeq = MKEY_SEQ_SCAN_READ_OUT2;
			break;
		case MKEY_SEQ_SCAN_READ_OUT2:
			ucKEY_Matrix[1] = KEY_IN;
			ucKEY_MatrixCnt = ucKEY_MatrixCnt + KEY_ReadKeyCnt(ucKEY_Matrix[1]);
			KEY_OUT_DIR(0x04);
			KEY_OUT(0x04);
			ucKEY_MatrixSeq = MKEY_SEQ_SCAN_READ_OUT3;
			break;
		case MKEY_SEQ_SCAN_READ_OUT3:
			ucKEY_Matrix[2] = KEY_IN;
			ucKEY_MatrixCnt = ucKEY_MatrixCnt + KEY_ReadKeyCnt(ucKEY_Matrix[2]);
			KEY_OUT_DIR(0x08);
			KEY_OUT(0x08);
			ucKEY_MatrixSeq = MKEY_SEQ_SCAN_READ_OUT4;
			break;
		case MKEY_SEQ_SCAN_READ_OUT4:
			ucKEY_Matrix[3] = KEY_IN;
			ucKEY_MatrixCnt = ucKEY_MatrixCnt + KEY_ReadKeyCnt(ucKEY_Matrix[3]);
			
			LOG_MATRIX("KEY_MatrixCnt:%d",ucKEY_MatrixCnt);
			LOG_MATRIX("KEY_Matrix[0]=0x%X",ucKEY_Matrix[0]);
			LOG_MATRIX("KEY_Matrix[1]=0x%X",ucKEY_Matrix[1]);
			LOG_MATRIX("KEY_Matrix[2]=0x%X",ucKEY_Matrix[2]);
			LOG_MATRIX("KEY_Matrix[3]=0x%X",ucKEY_Matrix[3]);
			KEY_MakeMatrixKey();
			if  (ucKEY_MatrixCnt == 0)
			{
				ucKEY_MatrixSeq = MKEY_SEQ_PRESCAN;
				ucKEY_MatrixKey = KEY_NONE;
				KEY_OUT_DIR(0x0F);
				KEY_OUT(0x0F);
			}
			else
			{
				ucKEY_MatrixSeq = MKEY_SEQ_SCAN_READ_OUT1;
				ucKEY_MatrixCnt = 0;
				KEY_OUT_DIR(0x01);
				KEY_OUT(0x01);
			}

			break;
	}
}


#define	AD_VAL(X)	(X * 1023) / 3.3
#define	AD_TOLERANCE_H(X)	AD_VAL(X + (X * 0.05))
#define	AD_TOLERANCE_L(X)	AD_VAL(X + (X * 0.05))

KEY_ID	ucADKeyLast[4];
unsigned char ucADKey_Cnt;

unsigned short usADKey_Value[8];

unsigned short KEY_RemoteAD_Cal(void)
{
	unsigned short usAvg = 0xFFFF;
	unsigned char i;
	unsigned long Sum = 0;
	unsigned short usSumCnt = 0;
	unsigned short usMax;
	unsigned short usMin;

	for(i = 0; i < 8; ++i)
	{
		usADKey_Value[i] = CPU_ADC_GetRemoconLevel();
		
		if  (i == 0)
		{
			usMax = usADKey_Value[0];
			usMin = usADKey_Value[0];
		}
		else
		{
			if  (usMax < usADKey_Value[i])
			{
				usMax = usADKey_Value[i];
			}
			if  (usMin > usADKey_Value[i])
			{
				usMin = usADKey_Value[i];
			}
		}
	}
	
	if  (usMax == usMin)
	{
		usAvg = usMax;
	}
	else
	{
		for(i = 0; i < 8; ++i)
		{
			if  ((usMax != usADKey_Value[i]) && (usMin != usADKey_Value[i]))
			{
				Sum = Sum + usADKey_Value[i];
				++usSumCnt;				
			}
		}

		if  (usSumCnt == 0)
		{
			Sum = usMax + usMin;
			usAvg = Sum/2;
		}
		else
		{
			usAvg = Sum/usSumCnt;
		}
	}

	return(usAvg);
}

void KEY_RemoteInput(void)
{
	KEY_ID ucNewKey = KEY_NONE;

	if  (ucKEY_Rmc_Timer5msec != 0)
	{
		return;
	}

	ucKEY_Rmc_Timer5msec = 10/5;
	usCPU_ADC_Rmc = KEY_RemoteAD_Cal();
	
	if  ((AD_VAL(3.10) > usCPU_ADC_Rmc) && (AD_VAL(2.60) < usCPU_ADC_Rmc))	// 2.83
	{
		ucNewKey = KEY_POWER;// Power
	}
	if  ((AD_VAL(2.59) > usCPU_ADC_Rmc) && (AD_VAL(1.85) < usCPU_ADC_Rmc))	// 2.06
	{
		ucNewKey = KEY_RMC_MODE;// Mode
	}
	if  ((AD_VAL(1.84) > usCPU_ADC_Rmc) && (AD_VAL(1.45) < usCPU_ADC_Rmc))	// 1.64
	{
		ucNewKey = KEY_RMC_VOL_UP;// Track Up
	}
	if  ((AD_VAL(1.44) > usCPU_ADC_Rmc) && (AD_VAL(0.10) < usCPU_ADC_Rmc))	// 1.24
	{
		ucNewKey = KEY_RMC_VOL_DOWN;// Track Down
	}
	
	ucADKeyLast[ucADKey_Cnt] = ucNewKey;
	if  (++ucADKey_Cnt > 2)
	{
		ucADKey_Cnt = 0;
		if  ((ucADKeyLast[0] == ucADKeyLast[1]) && (ucADKeyLast[1] == ucADKeyLast[2]))
		{
			ucKEY_RmcKey = ucNewKey;
		}
	}
		
	usCPU_ADC_Rmc = 0xFFFF;
}

unsigned char ucVolumeEnc_Last;
unsigned char ucVolumeEnc_UpFlag;
unsigned char ucVolumeEnc_DownFlag;
unsigned char ucTuneEnc_Last;
unsigned char ucTuneEnc_UpFlag;
unsigned char ucTuneEnc_DownFlag;

void KEY_VolumeEncoderInput(void)
{
	unsigned char ucTemp;

#ifdef  MODEL_ARA5040
	ucTemp = (p0 >> 3) & 0x03;
#endif
#ifdef  MODEL_AGC5030
	ucTemp = (p0 >> 1) & 0x03;
#endif
#ifdef  MODEL_AGC505X
	ucTemp = (p0 >> 1) & 0x03;
#endif

	switch  (ucTemp)
	{
		case	0x00:
			if  (ucVolumeEnc_Last == 0x01)
			{
				if  (ucVolumeEnc_DownFlag == 1)
				{
					ucKEY_EncVolKey = KEY_VOL_DOWN;
					LOG_KEY("VOL DOWN");
				}
			}
			if  (ucVolumeEnc_Last == 0x02)
			{
				if  (ucVolumeEnc_UpFlag == 1)
				{
					ucKEY_EncVolKey = KEY_VOL_UP;
					LOG_KEY("VOL UP");
				}
			}
			ucVolumeEnc_UpFlag = 0x00;
			ucVolumeEnc_DownFlag = 0x00;
			break;
		case	0x01:
			if  (ucVolumeEnc_Last == 0x00)
			{
				ucVolumeEnc_UpFlag = 1;
			}
			if  (ucVolumeEnc_Last == 0x03)
			{
				ucVolumeEnc_DownFlag = 1;
			}
			break;
		case	0x02:
			if  (ucVolumeEnc_Last == 0x00)
			{
				ucVolumeEnc_DownFlag = 1;
			}
			if  (ucVolumeEnc_Last == 0x03)
			{
				ucVolumeEnc_UpFlag = 1;
			}
			break;
		case	0x03:
			if  (ucVolumeEnc_Last == 0x01)
			{
				if  (ucVolumeEnc_UpFlag == 1)
				{
					ucKEY_EncVolKey = KEY_VOL_UP;
					LOG_KEY("VOL UP");
				}
			}
			if  (ucVolumeEnc_Last == 0x02)
			{
				if  (ucVolumeEnc_DownFlag == 1)
				{
					ucKEY_EncVolKey = KEY_VOL_DOWN;
					LOG_KEY("VOL DOWN");
				}
			}
			ucVolumeEnc_UpFlag = 0x00;
			ucVolumeEnc_DownFlag = 0x00;
			break;
	}
	ucVolumeEnc_Last = ucTemp;
}
	
void KEY_TuneEncoderInput(void)
{
	unsigned char ucTemp;

#ifdef  MODEL_ARA5040
	ucTemp = (p0 >> 1) & 0x03;
#endif
#ifdef  MODEL_AGC505X
	ucTemp = (p0 >> 3) & 0x03;
#endif
#ifdef  MODEL_AGC5030
	ucTemp = (p0 >> 3) & 0x03;
#endif

#ifdef  MODEL_AGC505X
	switch  (ucTemp)
	{
		case	0x00:
			if  (ucTuneEnc_Last == 0x01)
			{
				if  (ucTuneEnc_DownFlag == 1)
				{
					ucKEY_EncTuneKey = KEY_TUNE_DOWN;
					LOG_KEY("TUNE DOWN");
				}
			}
			if  (ucTuneEnc_Last == 0x02)
			{
				if  (ucTuneEnc_UpFlag == 1)
				{
					ucKEY_EncTuneKey = KEY_TUNE_UP;
					LOG_KEY("TUNE UP");
				}
			}
			ucTuneEnc_UpFlag = 0x00;
			ucTuneEnc_DownFlag = 0x00;
			break;
		case	0x01:
			if  (ucTuneEnc_Last == 0x00)
			{
				ucTuneEnc_UpFlag = 1;
			}
			if  (ucTuneEnc_Last == 0x03)
			{
				ucTuneEnc_DownFlag = 1;
			}
			break;
		case	0x02:
			if  (ucTuneEnc_Last == 0x00)
			{
				ucTuneEnc_DownFlag = 1;
			}
			if  (ucTuneEnc_Last == 0x03)
			{
				ucTuneEnc_UpFlag = 1;
			}
			break;
		case	0x03:
			if  (ucTuneEnc_Last == 0x01)
			{
				if  (ucTuneEnc_UpFlag == 1)
				{
					ucKEY_EncTuneKey = KEY_TUNE_UP;
					LOG_KEY("TUNE UP");
				}
			}
			if  (ucTuneEnc_Last == 0x02)
			{
				if  (ucTuneEnc_DownFlag == 1)
				{
					ucKEY_EncTuneKey = KEY_TUNE_DOWN;
					LOG_KEY("TUNE DOWN");
				}
			}
			ucTuneEnc_UpFlag = 0x00;
			ucTuneEnc_DownFlag = 0x00;
			break;
	}
	ucTuneEnc_Last = ucTemp;
#else
	if  (ucTuneEnc_Last == ucTemp)
	{
		ucKEY_EncTuneKey = KEY_NONE;
		if  (ucTemp == 0x02)
		{
			ucKEY_EncTuneKey = KEY_TUNE_DOWN;
		}
		if  (ucTemp == 0x01)
		{
			ucKEY_EncTuneKey = KEY_TUNE_UP;
		}
	}
	ucTuneEnc_Last = ucTemp;
#endif
#if  0
	ucKEY_EncTuneKey = KEY_NONE;

	switch  (ucTemp)
	{
		case	0x00:
			if  (ucTuneEnc_Last == 0x01)
			{
				if  (ucTuneEnc_DownFlag == 1)
				{
					ucKEY_EncTuneKey = KEY_TUNE_DOWN;
				}
			}
			if  (ucTuneEnc_Last == 0x02)
			{
				if  (ucTuneEnc_UpFlag == 1)
				{
					ucKEY_EncTuneKey = KEY_TUNE_UP;
				}
			}
			ucTuneEnc_UpFlag = 0x00;
			ucTuneEnc_DownFlag = 0x00;
			break;
		case	0x01:
			if  (ucTuneEnc_Last == 0x00)
			{
				ucTuneEnc_UpFlag = 1;
			}
			if  (ucTuneEnc_Last == 0x03)
			{
				ucTuneEnc_DownFlag = 1;
			}
			break;
		case	0x02:
			if  (ucTuneEnc_Last == 0x00)
			{
				ucTuneEnc_DownFlag = 1;
			}
			if  (ucTuneEnc_Last == 0x03)
			{
				ucTuneEnc_UpFlag = 1;
			}
			break;
		case	0x03:
			if  (ucTuneEnc_Last == 0x01)
			{
				if  (ucTuneEnc_UpFlag == 1)
				{
					ucKEY_EncTuneKey = KEY_TUNE_UP;
				}
			}
			if  (ucTuneEnc_Last == 0x02)
			{
				if  (ucTuneEnc_DownFlag == 1)
				{
					ucKEY_EncTuneKey = KEY_TUNE_DOWN;
				}
			}
			ucTuneEnc_UpFlag = 0x00;
			ucTuneEnc_DownFlag = 0x00;
			break;
	}
	ucTuneEnc_Last = ucTemp;
#endif
}
#ifdef  CD
unsigned char ucKEY_EjectLast;
unsigned char ucKEY_Eject;

void KEY_EjectInput(void)
{
	unsigned char ucTemp;
	unsigned char i;

	ucTemp = PI_EJECT_KEY;

	for(i = 0; i < 10; ++i)
	{
		KEY_Delay(0);
		if  (ucTemp != PI_EJECT_KEY)
		{
			return;
		}
	}

	if  (ucTemp == ucKEY_EjectLast)
	{	
		if  (ucTemp == KEY_EJECT_ON)
		{
			ucKEY_Eject = KEY_EJECT;
		}
		else
		{
			ucKEY_Eject = KEY_NONE;
		}
	}
	ucKEY_EjectLast = ucTemp;
}
#endif

void KEY_InputMain(void)
{
	unsigned char ucTemp;

	if  (PWR_ProcessIsIdle() == 0)
	{
		return;
	}

	KEY_MatrixInput();
	CPU_ADC_GetValue();
	KEY_RemoteInput();
	KEY_VolumeEncoderInput();
	KEY_TuneEncoderInput();
	#ifdef  CD
	if  (OPT_GetOption(OPT_MASK_CD))
	{
		KEY_EjectInput();
	}
	#endif

	ucTemp = 0;

	if  (ucKEY_MatrixKey != KEY_NONE)
	{
		++ucTemp;
//		LOG_KEY("ucKEY_MatrixKey:%d",ucKEY_MatrixKey);
	}
	if  (ucKEY_RmcKey != KEY_NONE)
	{
		++ucTemp;
//		LOG_KEY("ucKEY_RmcKey:%d",ucKEY_RmcKey);
	}

#ifdef  LC786XXX_AUDIO
	if  (ucKEY_EncVolKey_Timer5msec == 0)
#endif
	{
		if  (ucKEY_EncVolKey != KEY_NONE)
		{
			++ucTemp;
		#ifdef  LC786XXX_AUDIO
			ucKEY_EncVolKey_Timer5msec = 30/5;
		#endif
	//		LOG_KEY("ucKEY_EncVolKey:%d",ucKEY_EncVolKey);
		}
	}
	if  (ucKEY_EncTuneKey != KEY_NONE)
	{
		++ucTemp;
	//	LOG_KEY("ucKEY_EncTuneKey:%d",ucKEY_EncTuneKey);
	}
#ifdef  CD
	if  (ucKEY_Eject != KEY_NONE)
	{
		++ucTemp;
//		LOG_KEY("ucKEY_Eject:%d",ucKEY_Eject);
	}
#endif
	if  (ucTemp == 0)
	{
		ucKEY_New = KEY_NONE;
	}
	if  (ucTemp == 1)
	{
		if  (ucKEY_MatrixKey != KEY_NONE)
		{
			ucKEY_New = ucKEY_MatrixKey;
		}
		if  (ucKEY_RmcKey != KEY_NONE)
		{
			ucKEY_New = ucKEY_RmcKey;
		}
		if  (ucKEY_EncTuneKey != KEY_NONE)
		{
			KEY_ShortKeyMain(ucKEY_EncTuneKey);
			ucKEY_EncTuneKey = 0;
	//		ucKEY_New = ucKEY_EncTuneKey;
		}
		if  (ucKEY_EncVolKey != KEY_NONE)
		{
			KEY_ShortKeyMain(ucKEY_EncVolKey);
			ucKEY_EncVolKey = 0;
		}
	#ifdef  CD
		if  (ucKEY_Eject != KEY_NONE)
		{
			ucKEY_New = ucKEY_Eject;
		}
	#endif
	}	
}

